blazing-threads / pdf-curator
一个PDF合并工具,解决并维护内部页面链接,包括跨文件内部链接。
dev-master
2018-03-18 00:45 UTC
Requires
- setasign/fpdi-fpdf: ^1.6
This package is not auto-updated.
Last update: 2024-09-29 01:58:59 UTC
README
这是一个PDF文件合并工具,解决并维护内部页面链接,包括跨文件内部链接。 PDF Curator 扩展了 FPDF & FPDI 以保留内部链接,因为这些库的当前版本不支持。 PDF Curator 还为创建在合并的文件中工作的内部链接建立了规范。
使用方法
此包主要开发用于启用 CLI Press 所需的功能。目前没有关于如何使用它的详细文档。这里看到的就是你得到的。
<?php
$curator = new BlazingThreads\PdfCurator\Curator();
// files are merged in the order that you add them to the Curator
// add some files
foreach (glob('*.pdf') as $file) {
$this->curator->addFile($file);
}
// you can also prepend files, so `../cover.pdf` will be the first page
$this->curator->prependFile('../cover.pdf');
// the `merge` method will give you back the merged file as a string.
// save it somewhere.
if (file_put_contents('output.pdf', $this->curator->merge())) {
echo 'pdf files merged';
} else {
echo 'oops! something broke';
}
特殊链接
如果你想让一个PDF链接到另一个也正在合并的PDF,你必须设置特殊格式的链接。这些链接必须是基于URI的链接,引用页面 curator
并带有指向命名目标的哈希。示例包括
https:///curator#some-named-destination
file://tmp/curator#some-named-destination
PDF Curator 只查找 /curator
和剩余的字符,所以URI链接的开始将被忽略,可以是任何内容。目标必须存在于要合并的文档之一(且仅限于一个)中。如果它在多个文档中存在,链接将被忽略,因为它无法解析。将URI链接放入PDF取决于你,但它们必须作为PDF资源流中的目标存在。
此外,还有一个特殊的命名目标格式,可以链接到最终文档中的特定页码。
https:///curator#curated-page-3
file://tmp/curator#curated-page-3
上面的示例将创建一个链接到最终文档的第3页。