如何将多个URL呈现为单个PDF

问题描述 投票:0回答:1

我正在尝试打开一系列URL来呈现输出,然后使用PhantomJS组合成一个PDF,但我找不到任何关于如何执行此操作的文档。我只是使用试验和错误,但没有到达任何地方 - 希望有人知道如何做到这一点。

我没有完全设置PhantomJS,所以如果你知道一个更好的命令行,节点或JAVA工具会更好,我都是耳朵(或者在这种情况下是眼睛)。

这是我提供单个页面的代码。我试过复制open / render,但它总是覆盖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
1个回答
1
投票

PhantomJS将一个网页呈现为一个PDF文件,因此如果您可以将多个URL合并为一个html文件,则可以在PhantomJS中打开它并制作PDF。

但是在脚本结束时制作几个PDF然后merge them into one with something like pdfkt会更简单,从PhantomJS child module启动合并命令

© www.soinside.com 2019 - 2024. All rights reserved.