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.
Here's how to convert a Chrome HTML web page to PDF:Browse to the desired web page. Click the More Options button —three vertical dots on the far-left of the browser's top ribbon. Click on the Print option. Change Destination to Save As PDF.
On a Windows computer, open an HTML web page in Internet Explorer, Google Chrome, or Firefox. On a Mac, open an HTML web page in Firefox. Click the “Convert to PDF” button in the Adobe PDF toolbar to start the PDF conversion. Enter a file name and save your new PDF file in a desired location.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With