【问题标题】:Merge/nest multiple PDF pages to one将多个 PDF 页面合并/嵌套为一个
【发布时间】:2018-07-22 16:47:30
【问题描述】:

我正在尝试编写一个小型电子应用程序,它将多个 pdf 文件或页面嵌套到一个更大的页面(用于在绘制大量 CAD 图纸时节省纸张)。

基本上,来自 pdfjam 的 unix 命令 pdfnup 是我想要的 - 但由于不同的操作系统(Mac 和 Windows),我需要一个跨平台解决方案。

到目前为止,有没有人用 node/javascript 做过类似的事情?经过大量研究,我还没有找到合理的解决方案或库。

【问题讨论】:

标签: javascript node.js pdf electron


【解决方案1】:

感谢 Zxifer 的回答,我偶然发现了 HummusRecipe 库,它为 HummusJS 项目提供了高级 API。覆盖方法是我一直在寻找的。​​p>

我最终得到了这段代码:

// Maximum plottable height (915 mm) - Conversion to point
const maxPageHeight = (915 / 0.3528);

// Read files and determine width/length of plot
const fileOne = new HummusRecipe('lp.pdf', 'output1.pdf');
const fileTwo = new HummusRecipe('ls.pdf', 'output2.pdf');
let width = Math.max(fileOne.pageInfo(1).width, fileTwo.pageInfo(1).width) + 30;

// Create new pdf file
const pdfDoc = new HummusRecipe('new', 'output.pdf', {
    version: 1.6,
    author: 'IBB Wörn Ingenieure GmbH',
    title: 'Print PDF',
    subject: 'Imposition of various PDF files for optimized printing.'
});

// Get height of first pdf to generate offsett
let heightOne = fileOne.pageInfo(1).height;
// Overlay PDFs to new pdf with offset and ~ 5mm margin
pdfDoc
    .createPage(width, maxPageHeight)
    .overlay('lp.pdf', 15, 15)
    .overlay('ls.pdf', 15, heightOne + 15)
    .endPage()
    .endPDF();

【讨论】:

    猜你喜欢
    • 2013-06-13
    • 2013-03-03
    • 2013-06-16
    • 2022-12-03
    • 1970-01-01
    • 1970-01-01
    • 2015-07-20
    • 1970-01-01
    相关资源
    最近更新 更多