Wht is the best solution for HTML to PDF (on Azure Web app) [closed]
Asked Answered
D

2

3

Actually I am trying to convert html content to pdf using NReco PDF converter, however, this line of code pdfDoc.GeneratePdf(HtmlContent); unable to get through on Azure web app, but it works normally on my dev environment. So my Question is which cloud service should i go for?

Deathly answered 15/10, 2015 at 3:25 Comment(0)
P
6

Azure Apps (former WebSites) operate in restricted (partial-trust) environment and wkhtmltopdf.exe (that is internally used by NReco PdfGenerator wrapper) cannot be executed in this case directly from asp.net application.

update:

Unfortunately it will not work with Azure WebJobs as well: tasks are executed under the same (limited) environment as WebSites and GDI functions used by wkhtmltopdf are disabled.

If your ASP.NET app uses wkhtmltopdf-based component for PDF generation (doesn't matter how it is invoked - in separate process or as native DLL API) it will work only under Azure WebRole / WorkerRole / VM.

-- update 2017 --

Wkhtmltopdf (and NReco PdfGenerator wrapper) can be used with Azure Apps with VM-based subscription plan (Basic or higher). At least one issue still exists: it seems fonts API is still restricted and custom fonts cannot be rendered to PDF.

Pollinize answered 15/10, 2015 at 15:22 Comment(6)
Thanks for your answer. I am not familiar with Azure WebJobs, can you give me a place to start in order to archive this?Deathly
A WebJob won't help as it runs under the same sandbox. See this document for sandbox details. At the end there is a list of unsupported frameworks.Heptagon
@David Ebbo I see. Then my only is to switch from web app service to cloud service web role?Deathly
Unfortunately, this may be your only option right now if you must use this component :(Heptagon
@David Ebbo You're absolutely right I forgot that wkhtmltopdf will not work under WebJobs because of GDI functions usage (I've updated my answer).Pollinize
@DavidEbbo Thanks for your advice. I did switched to cloud service and it is working now.Deathly
S
7

I've successfully managed to get wkhtmltopdf working on Azure functions backed by app service. I've used the OpenHtmltoPdf c# package which installs the wkhtmltopdf library automatically. I've published all the required files here:

https://gist.github.com/tmakin/80e1905094245c857c493b7879657095

Update July 2018
I've now switched to DinkToPdf for pdf on azure functions v2 which runs on net core. See here for more info:
https://odetocode.com/blogs/scott/archive/2018/02/14/pdf-generation-in-azure-functions-v2.aspx

Selfhelp answered 9/2, 2017 at 12:14 Comment(3)
I used DinkToPdf on Azure Functions V2 as well, but it stopped working. Is it still working for you?Consternation
Can this be used now too ? I have a requirement for converting HTML file to PDF in Azure Function.Welbie
I've now switched to AWS lambda for hosing DinkToPdf based pdf conversions. Way quicker and much more flexible.Selfhelp
P
6

Azure Apps (former WebSites) operate in restricted (partial-trust) environment and wkhtmltopdf.exe (that is internally used by NReco PdfGenerator wrapper) cannot be executed in this case directly from asp.net application.

update:

Unfortunately it will not work with Azure WebJobs as well: tasks are executed under the same (limited) environment as WebSites and GDI functions used by wkhtmltopdf are disabled.

If your ASP.NET app uses wkhtmltopdf-based component for PDF generation (doesn't matter how it is invoked - in separate process or as native DLL API) it will work only under Azure WebRole / WorkerRole / VM.

-- update 2017 --

Wkhtmltopdf (and NReco PdfGenerator wrapper) can be used with Azure Apps with VM-based subscription plan (Basic or higher). At least one issue still exists: it seems fonts API is still restricted and custom fonts cannot be rendered to PDF.

Pollinize answered 15/10, 2015 at 15:22 Comment(6)
Thanks for your answer. I am not familiar with Azure WebJobs, can you give me a place to start in order to archive this?Deathly
A WebJob won't help as it runs under the same sandbox. See this document for sandbox details. At the end there is a list of unsupported frameworks.Heptagon
@David Ebbo I see. Then my only is to switch from web app service to cloud service web role?Deathly
Unfortunately, this may be your only option right now if you must use this component :(Heptagon
@David Ebbo You're absolutely right I forgot that wkhtmltopdf will not work under WebJobs because of GDI functions usage (I've updated my answer).Pollinize
@DavidEbbo Thanks for your advice. I did switched to cloud service and it is working now.Deathly

© 2022 - 2024 — McMap. All rights reserved.