Merge multiple PDF files into one in PHP [closed]

风格不统一 提交于 2020-01-10 03:25:08

问题


I would like to merge multiple PDF files to one. The PDF files are on different sites so they should first be downloaded and merged to one.

We work with PHP and Codeigniter. Does somebody know an solution for my problem?


回答1:


yes. i have merged pdf's. Get the fpdf and fpdi libraries and put them in to the code igniter third party folder. then it is just a matter of reading the manual for fpdfi and merging the documents. use this to set up the libraries

 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/

then this snippet of code should give you an idea of how it works. note i have edited sections of this for clarity. this example streams the pdf file. you could just as easily save the file elsewhere.

    $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);

as for getting pdfs from other sites, firstly make sure you are allowed to do this, then it is matter of using cURL. (copy URL). there is a codeigniter library to do this, or you can use the PHP library.




回答2:


Reference Link :http://portfolio.floatbit.com/blog/merge-multiple-pdfs-php-using-shellexec

PDF Merge is also a solution

Reference Link :http://pdfmerger.codeplex.com/releases/view/37934



来源:https://stackoverflow.com/questions/19855712/merge-multiple-pdf-files-into-one-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!