【发布时间】:2020-12-30 10:12:11
【问题描述】:
我想将一个大的 html 文件(21 Mb,不包括照片)转换为 .pdf,但我无法做到
Javascript 或 python 甚至 CLI 中的解决方案都可以工作
我尝试了两种方法:
-
使用 html 节点
function writeToPdf(htmlpath, pdfpath) { const writeStream = fs.createWriteStream(pdfpath); const options = { format: "Letter" }; const html = fs.readFileSync(htmlpath, "utf8"); return new Promise(function (resolve, reject) { pdf.create(html, options).toStream(function (err, stream) { stream.pipe(writeStream); }); writeStream.on("error", function (err) { console.log(err); reject(err); }); resolve({}); }); } let htmlpath = 'input.html'; let outpath = 'output.pdf'; writeToPdf(htmlpath, outpath)
这适用于小 html 文件,但会卡住,或者我不知道大 html 文件处理了多少文件
- 我在 windows 上使用 wkhtmltopdf,但在 50% 的时候卡住了几次
任何帮助对我来说都会很棒,包括 JavaScript 或 Python
【问题讨论】:
-
pandoc 呢?
-
是 html 到 pdf 或流,因为输入很大
-
我无法猜测你的情况,但对我来说,通过 LaTeX 在 .md 到 .pdf 导出中工作,在包含大量图像和表格的两列的 389 页密集文本的文档中,所以...
标签: python node.js wkhtmltopdf html-to-pdf node-pdfkit