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

帅比萌擦擦* 提交于 2020-01-03 04:51:29

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/33139317/wht-is-the-best-solution-for-html-to-pdf-on-azure-web-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!