在Azure Function中将HTML转换为Pdf库
Azure函数显然还不支持 System.Drawing
( sanbox信息)。运行对其具有依赖项的函数会引发以下消息:
Azure functions apparently doesn't yet support System.Drawing
(sanbox info). Running a function with a dependency on it throws the following message:
System.Drawing is not supported on this platform.
我最初使用的是 Select.HtmlToPdf 可以从HTML创建PDF文档。但是,由于将PDF生成移至Azure函数,因此不再是这种选择。
I was originally using Select.HtmlToPdf in a WebApp to create PDF documents from HTML. But, since moving the PDF generation to an Azure function, that is no longer an option.
此外,推荐的库为 wkhtmltopdf
,但似乎没有 .netstandard2.0
版本。
Also, the reccomended library is wkhtmltopdf
, but that doesn't seem to have a .netstandard2.0
version.
如何使用Azure Functions(C#)完成PDF生成?
How would you accomplish PDF generation using Azure Functions (C#)?
更新:该功能正在S1-App服务计划上运行。
Update: the function is running on an S1 - App Service Plan.
更新2:使用 OdeToCode 给出错误 Qt:无法初始化OLE(错误80010106)
Update2: using the method shown on OdeToCode gives the error Qt: Could not initialize OLE (error 80010106)
这时我创建了一个新的 netcore2.0
支持 Select.HtmlToPdf
的Azure AppService API,如果仍然不支持,则可能会将此功能移动到容器中不久后就可以使用 netcore3.0
了。
该函数仅使用一些参数调用API,并且可以等待PDF生成异步。
At this point I created a new netcore2.0
Azure AppService API that supports Select.HtmlToPdf
and will probably move this functionality to a container if it still doesn't work with netcore3.0
in a little while.
The function just calls the API with some parameters and can wait for the PDF generation async.
为 Jerry 已经提到,它可能与 DinkToPdf 。但是,模板html文档中不得包含JavaScript,因此该解决方案对我的用例无效。
As Jerry has mentioned, it might work with DinkToPdf. However, the template html docs must not contain JavaScript, so this solution is not valid for my use-case.