【发布时间】:2017-12-21 21:54:07
【问题描述】:
我正在尝试打开一系列 URL 来呈现输出,然后使用 PhantomJS 组合成一个 PDF,但我找不到任何有关如何执行此操作的文档。我只是在反复试验,但没有取得任何进展 - 希望有人知道如何做到这一点。
我还没有完全使用 PhantomJS,所以如果你知道更好的命令行、节点或 JAVA 工具会更好,我会全神贯注(或者在这种情况下是眼睛)。
这是呈现单个页面的代码。我试过复制打开/渲染,但它总是覆盖 PDF 而不是附加到它。
var page = require('webpage').create(),
system = require('system'),
fs = require('fs'),
pages = {
page1: 'http://localhost/test1.html',
page2: 'http://localhost/test2.html'
};
page.paperSize = {
format: 'A4',
orientation: 'portrait',
};
page.settings.dpi = "96";
// this renders a single page and overwrites the existing PDF or creates a new one
page.open('pages.page1', function() {
setTimeout(function() {
page.render('capture.pdf');
phantom.exit();
}, 5000);
});
【问题讨论】:
标签: phantomjs pdf-generation html-to-pdf