我想将多个PDF文件合并为一个。 PDF文件位于不同的站点上,因此应首先将它们下载并合并为一个。
我们使用PHP和Codeigniter。有人知道我的问题的解决方案吗?
答案 0 :(得分:6)
是肯定的。我合并了pdf。 获取fpdf和fpdi库并将它们放入代码点火器第三方文件夹中。 那么只需阅读fpdfi的手册并合并文档即可。 用它来设置库
require_once("application/third_party/fpdf/fpdf.php");//http://www.fpdf.org/
require_once("application/third_party/fpdi/FPDI_Protection.php");//http://www.setasign.de/products/pdf-php-solutions/fpdi/
然后这段代码应该让你知道它是如何工作的。请注意,为了清晰起见,我已编辑了部分内容此示例流式传输pdf文件。您可以轻松地将文件保存在其他位置。
$files = array(<file full paths here>);
$pdf = new FPDI_Protection();
if ($data->password)
{
$pdf->setProtection(array(),$data->password);
}
for ($i = 0; $i < count($files); $i++ )
{
$pagecount = $pdf->setSourceFile($files[$i]);
for($j = 0; $j < $pagecount ; $j++)
{
$tplidx = $pdf->importPage(($j +1), '/MediaBox'); // template index.
$pdf->addPage('L','A4');// orientation can be P|L
$pdf->useTemplate($tplidx, 0, 0, 0, 0, TRUE);
}
unlink($files[$i]); // you may not want to unlink the files!
}
$dt = new DateTime(NULL, new DateTimeZone($data->user->timezone));
// set the metadata.
$pdf->SetAuthor($data->user->user_name);
$pdf->SetCreator('website name!');
$pdf->SetTitle('PDF, created: '.$dt->format(MYHMRS_DATETIME_FRIENDLY));
$pdf->SetSubject('PDF subject !');
$pdf->SetKeywords('website name!'.", keywords! ".$data->user->user_name);
$output = $pdf->Output('', 'S');
$name = "PDF".'-'.$dt->format('ymd').'.pdf';
$this->output
->set_header("Content-Disposition: filename=$name;")
->set_content_type('Application/pdf')
->set_output($output);
至于从其他网站获取pdf,首先要确保你可以这样做,然后就是使用cURL了。 (复制URL)。有codeigniter library to do this,或者您可以使用PHP library。
答案 1 :(得分:2)