I am trying to create an Azure Function App that merges a set of documents into a single PDF. I also need to convert some images to PDF and include those in the merged output file.
I have a working Power Automate Desktop flow that uses PowerShell scripts to run ImageMagick to convert images to PDF and GhostScript to merge all the PDF documents to a single PDF output file. I want to port my PAD flow and PowerShell scripts to an Azure Function App to hopefully speed up the runtime and response time to a Power Apps canvas app.
A bonus goal would be to fill .docx templates with data and convert them to PDFs first, then run the merge scripts and output the filled and merged document for consumption by Power Apps.
Let me simplify my question by focusing specifically on just the GhostScript aspect of this project. My issue is that when I try to run dotnet add package GhostScript.NET --version 1.2.3
I get the following output:
warn : NU1701: Package 'Ghostscript.NET 1.2.3' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project.
I am using Azure Functions runtime version ~4 and .NET version 6.0.403. Here is what my .csproj looks like:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GhostScript.NET" Version="1.2.3" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
In my 'HttpTrigger1.cs' file, when importing GhostScript.NET with using GhostScript.NET;
I get the following error:
The type or namespace name 'GhostScript' could not be found (are you missing a using directive or an assembly reference?)
Any ideas how I can correct these issues? I'm using VSCode to edit the project and GitHub for continuous deployment to the function app.
I tried making a new project with a downgraded .NET version of 3.X but that gave even more errors when I tried to restore the project after importing GhostScript.NET. I'm not even sure why I need GhostScript.NET...
I was following this old blog, which is quite out of date: http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/3303/Convert-PDF-files-to-PNG-Images-using-Azure-Functions.aspx
My PowerShell script, which runs in a local VM and works fine, just requires installing GhostScript with 'gs9550w64.exe'. That's the installer executable for GhostScript V9.55.0. The blog post above says I need to put the .dll from that GhostScript installation into the GhostScript.NET directory like /data/Functions/packages/nuget/ghostscript.net/1.2.1/lib/net40/gsdll64.dll. Granted, I have the 64 bit .dll but the blog is using 32 bit and the default Azure Function App platform is 32 bit, so I will have to decide what to do about that later, but I'm not even to that point yet. Also, that blog uses GhostScript.NET V1.2.1, but the latest version is 1.2.3. Anyway, I'm not even getting that far because of the errors I'm seeing when trying to install the GhostScript.NET package to this project.
Your help is greatly appreciated!