Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top