gabrielchavezme/pdf-table-of-content

1.0.5 2021-10-20 23:51 UTC

This package is auto-updated.

Last update: 2024-09-21 06:06:16 UTC


README

   

PHP 和 Laravel 的 PDF 合并及目录表解决方案

此包是 TCPDF 类的包装器,提供了一个优雅的 API 用于合并 PDF 文件,并返回带有书签的目录表。

该库基于以下源代码: karriereat/pdf-merge

使用了相同的代码结构,并增加了在添加的每个文档中创建书签的功能,之后返回包含文档目录表的数组,以便在前端侧的 JS 引擎中渲染。

安装

您可以通过 composer 安装此包

composer require gabrielchavezme/pdf-table-of-content

用法

$pdfMerge = new PdfTableOfContent();

$pdfMerge->add([
    'file' => '/path/to/file1.pdf',
    'title' => 'File 1',
    'id' => 1
]);
$pdfMerge->add([
    'file' => '/path/to/file2.pdf',
    'title' => 'File 2',
    'id' => 2
]);

$pdfMerge->merge('/path/to/output.pdf');

请注意,如果未添加文件,则 merge 方法将抛出 NoFilesDefinedException 异常。

检查文件存在性

您可以通过调用以下方式检查文件是否已添加用于合并:

$pdfMerge->contains('/path/to/file.pdf');

许可证

Apache License 2.0 请参阅 LICENSE 获取更多信息。