【发布时间】:2017-02-10 14:06:49
【问题描述】:
我有一个生成 PDF 文件的系统,每个文件由两页组成。出于某种原因,我需要编写一个 PHP 代码,它可以从每个 PDF 文件中删除第二页。以下是我所做的以及结果如何:
1- 我使用TCPDF库编写了以下代码:
require_once('TCPDF-master/examples/tcpdf_include.php');
require_once('TCPDF-master/tcpdf_import.php');
$pdf = new TCPDF_IMPORT( 'test.pdf' );
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
$pdf->deletePage(2);
$pdf->Output('test_output.pdf', 'I');
结果:空白一页 PDF 文件。换句话说,原始文件中的内容在新文件中不可用
2- 我使用 FPDF 和 FPDI 库从原始文件中仅读取一页。
require_once('FPDF-master/fpdf.php');
require_once('FPDI-1.6.1/fpdi.php');
$pdf = new FPDI();
$pageCount = $pdf->setSourceFile('test.pdf');
$tplIdx = $pdf->importPage(1, '/MediaBox');
$pdf->addPage();
$pdf->useTemplate($tplIdx, 10, 10, 90);
$pdf->Output();
结果是这个错误信息:
未捕获的异常 'Exception' 带有消息 'This document (test.pdf) 可能使用了不支持的压缩技术 FPDI 附带的免费解析器。 (看 https://www.setasign.com/fpdi-pdf-parser 了解更多详情)' C:\wamp\www\FPDI-1.6.1\pdf_parser.php 在第 322 行
有人知道怎么帮忙吗?
【问题讨论】:
-
您是否尝试过该链接中的解析器?也许您需要商业插件才能打开您的源文件。
-
比较贵的问题,不能用,正在找免费的解决方案
-
看看这个stackoverflow.com/questions/14546275/…,你可以根据需要修改