Trying to set up the Html to PDF Converter in an Azure Function. Had it working locally using Blink libraries, then read that Blink doesn't work in an Azure Function, so I tried switching to WebKit. When I switched to WebKit, I am getting a System.IO.FileNotFoundException 'Could not load file or assembly System.Windows.Forms'.
This is the line that I'm receiving the error on... (where doc is of type PdfDocument, and myStream is of type either MemoryStream or FileStream - neither seem to work).
doc.Save(myStream);
Now, if I try to switch back to Blink libraries that isn't working either. I get the same exception (looking for System.Windows.Forms) but on this line instead:
HtmlToPdfConverter converter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink);
The Nuget package I have installed is Syncfusion.HtmlToPdfConverter.QtWebKit.Net.Core. I have spent so much time troubleshooting this and looking through the various Syncfusion tutorials to get this working. Can't figure out what has gone wrong. At this point I just want to get it working locally, then I'll deal with the issues that people seems to have getting it to work directly in Azure.
Environment:
Hi AB,
We did not face this type of exception before. We have created a simple Net 6.0 sample for converting Html to PDF documents using the WebKit rendering engine, it works properly and generates a PDF document in both memory stream and file stream. We request you to refer to the same product version of Syncfusion assemblies across different projects (dependent ones). We have attached the sample with the output document for your reference, please try the below sample on your end and let us know the result.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/HtmlNet6.01959953116
Please refer to the below documentation,
UG: https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/webkit#url-to-pdf
Blogs: https://www.syncfusion.com/blogs/post/html-to-pdf-conversion-in-csharp.aspx
Please let us know if you need any further assistance in this.
Regards,
Gowthamraj K
Thank you for the sample. I had a look and I have everything set up exactly the same. What I ended up doing was creating an entirely new Azure Functions project in Visual Studio and then copied all of my classes over to the new project, installed the appropriate Nuget packages, and now it's working again locally. So something must have been corrupt in the old project, especially since I had it working at one point.
Now however, I am unable to get it working when published to Azure. I am getting the dreaded "Html conversion failed" message. I am on a B1 app service plan, have set to 64-bit runtime, and I have confirmed in the console that the "bin\QtBinariesWindows" folder has all of the files copied into it. Any idea what else may be causing such an issue when it is working fine locally?
Hi AB,
We have further analyzed about the reported issue, it is occurring due to QtBinariesWindows folder is not copied properly to the Azure SDK. So, the reported HTML Conversion failed exception occurs.
We can resolve this issue by copying all the files in the QtBinariesWindows and set the proper path. Please ensure all the files and inner folder are properly copied in Azure server using console in Azure portal. If it is not copied, kindly add all the files manually to resolve that issue. This is not an issue in our library. Please follow the below steps to copy the files properly to resolve the reported issue.
|
|
|
cp *.* c:\home\site\wwwroot\QtBinariesWindows\ |
|
cp *.* c:\home\site\wwwroot\QtBinariesWindows\platforms |
|
cp *.* c:\home\site\wwwroot\QtBinariesWindows\imageformats |
Please refer to the below links to troubleshooting the WebKit HTML converter.
Troubleshooting: https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/webkit#troubleshooting
Please refer the below KB steps for more information,
Azure (V2): https://www.syncfusion.com/kb/10301/how-to-convert-html-to-pdf-in-azure-functions-2-0
Our HTML converter internally creates and launches a surrogate process from a temporary folder. So, the converter is required to read/write and execute permission of the temporary folder. So, please check the temporary folder has read/write/execute permission for the respective user group. For converting HTML to PDF in Azure, we internally launch the browser process from the QtBinariesWindows folder. We need to publish the function without a run from the package option (refer below screenshot) and let us know the result.
Please try the above suggestion and let us know the result.
Regards,
Gowthamraj K
Thank you - the trick here was not running the function from a package file so that I could complete the commands in the console. Everything is working well now.
Hi AB,
Thank you for your update. We are glad to know that your problem has been solved. Please let us know if you require further assistance with this.
Regards,
Gowthamraj K