使用Chrome浏览器pdfium进行HTML到PDF的转换 [英] HTML to PDF conversion using Chrome pdfium

查看:471
本文介绍了使用Chrome浏览器pdfium进行HTML到PDF的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以建议如何使用chrome pdfium将HTML转换为PDF。



既然,我尝试了pdf.js和其他一些,但它并没有给我一个适当的结果。



我认为chrome pdfium可以正确处理它们。所以,我想尝试使用pdfium从HTML源代码生成PDF文件。



谢谢。

解决方案

PDFium (和 PDF.js )仅仅是PDF阅读器,您无法将HTML转换为PDF。



Chrome中的实际PDF生成由完成使用 Blink (渲染引擎)和 code.google.com/p/skia/rel =noreferrer> Skia (图形堆栈)。为了使第三方项目可以使用打印功能( crbug.com/311308 ),但它仍在进行中。

Chrome 59 用于通过 - print-to-pdf 标志将HTML转换为PDF。有关特定功能本身,请参见 crbug.com/603559 , a href =https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md =noreferrer> https://chromium.googlesource.com/chromium/src/+/ lkgr / headless / README.md 以获取有关无头铬的文档。此示例加载example.com并将结果输出到`path / to / file.pdf。

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

如果您想知道如何在JavaScript中使用Chrome的内置PDF生成器,请遵循以下问题(尚未回答):程序的Javascript调用。 Chrome对话框打印功能


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.

解决方案

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.

这篇关于使用Chrome浏览器pdfium进行HTML到PDF的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆