langleyfoxall/pdf-stitcher

将多个PDF文件拼接在一起

v1.3.1 2023-05-15 13:08 UTC

This package is auto-updated.

Last update: 2024-09-15 16:03:26 UTC


README

PDF Stitcher库允许您轻松地将多个PDF文件拼接成一个单独的文件。

安装

要安装PDF Stitcher包,请运行以下Composer命令。

composer require langleyfoxall/pdf-stitcher

请注意,此包需要在您的服务器上安装Ghostscript(gs)。如果您正在运行Ubuntu,可以使用以下命令安装。

sudo apt install ghostscript

使用方法

请参考以下基本使用示例。

(new PdfStitcher)
    ->addPdf('firstDocument.pdf')
    ->addPdfs(['secondDocument.pdf', 'yetAnotherDocument.pdf'])
    ->save('destinationDocument.pdf');

这将接受三个输入PDF文件,将它们拼接在一起,并将结果保存到destinationDocument.pdf中。文件将按照添加的顺序拼接。

当Ghostscript位于不寻常的位置时

可以将Ghostscript可执行文件的路径传递给PdfStitcher构造函数

new PdfStitcher('a/path/to/a/gs/executable')

额外的Ghostscript参数

可以将额外的Ghostscript参数传递给PdfStitcher构造函数

new PdfStitcher(null, '-dNEWPDF=false')

这些参数将不会以任何方式进行转义。

仅包含PDF中的特定页面

在添加PDF时,您可以可选地给出一个页面索引数组

(new PdfStitcher)
    ->addPdf('firstDocument.pdf', [0, 2, 3, 5])
    ->save('destinationDocument.pdf');

仅包含您列出的页面编号。

以下将被拒绝

  • 非整数页面编号。
  • 页面编号小于零。
  • 重复的页面编号(例如:1, 3, 3, 5, 7)。
  • 页面编号顺序错误(例如:1, 5, 3, 7)。