HTML to PDF conversion using Chrome pdfium

我是研究僧i 提交于 2019-12-17 23:27:46

问题


Can anyone suggest how to convert HTML to PDF using chrome pdfium.

Since, I tried pdf.js and few other, but It is not giving me a proper result.

I think chrome pdfium handle them properly. So, I would like to give a try to pdfium for generating PDF file from HTML source.

Thanks.


回答1:


PDFium (and PDF.js) are merely PDF Viewers, you cannot convert HTML to PDF with them.

The actual PDF generation in Chrome is done by the printing component using Blink (the rendering engine) and Skia (the graphic stack). There is an effort going on to decouple the printing functionality from the printing UI so that third-party projects can use the printing functionality (crbug.com/311308), but it is still work-in-progress.
Chrome 59 and up can be used to convert HTML to PDF, via the --print-to-pdf flag. See crbug.com/603559 for the specific feature itself, and https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md for documentation about headless Chromium in general. This example loads example.com and outputs the result to `path/to/file.pdf.

chrome --headless --print-to-pdf=path/to/file.pdf https://example.com

If you want to know how to use Chrome's built-in PDF generator in JavaScript, follow the following question (which has not been answered yet): Javascript call programmatically the "Save as PDF" feature of Chrome dialog print.



来源:https://stackoverflow.com/questions/26555877/html-to-pdf-conversion-using-chrome-pdfium

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