我想将多个PDF文件合并到一个。 PDF文件在不同的站点上,因此应首先下载并合并到一个。

我们与PHP和CodeIgniter合作。有人知道解决我的问题吗?

有帮助吗?

解决方案

是的。我合并了PDF。得到 FPDFfpdi 库并将其放入“ IGNITER第三方文件夹”中。然后,这只是阅读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,首先确保您可以执行此操作,然后使用卷发。 (复制URL)。有一个 Codeigniter库来执行此操作, ,或者您可以使用 PHP库.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top