我使用fpdf和fpdi将pdf分成不同的单页。一切正常,但pdf内部的链接无法正常工作。在拆分的单页上删除了链接。
split_pdf("test.pdf", 'splitedpdf/');
function split_pdf($filename, $end_directory = false)
{
require_once('fpdf/fpdf.php');
require_once('fpdi/fpdi.php');
$end_directory = $end_directory ? $end_directory : './';
$new_path = preg_replace('/[\/]+/', '/', $end_directory.'/'.substr($filename, 0, strrpos($filename, '/')));
if (!is_dir($new_path))
{
// Will make directories under end directory that don't exist
// Provided that end directory exists and has the right permissions
mkdir($new_path, 0777, true);
}
$pdf = new FPDI();
$pagecount = $pdf->setSourceFile($filename); // How many pages?
// Split each page into a new PDF
for ($i = 1; $i <= $pagecount; $i++) {
$new_pdf = new FPDI();
$new_pdf->AddPage();
$new_pdf->setSourceFile($filename);
$new_pdf->useTemplate($new_pdf->importPage($i));
try {
$new_filename = $end_directory.str_replace('.pdf', '', $filename).'_'.$i.".pdf";
$new_pdf->Output($new_filename, "F");
echo "Page ".$i." split into ".$new_filename."<br />\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}
// $pdf->close();
}
答案 0 :(得分:2)
FPDI is not able to handle any dynamic content链接链接,表单字段或任何其他注释类型。其中an extension至少支持链接(仅与FPDI 1.4.4 + FPDF_TPL 1.2.3兼容)。
如果您需要提取包含所有附加注释的页面,您可以查看SetaPDF-Merger component(不是免费的!)。