Merge PDF files with PHP [closed]

Tags: ,

My concept is – there are 10 pdf files in a website. User can select some pdf files and then select merge to create a single pdf file which contains the selected pages. How can i do this with php?


I’ve done this before. I had a pdf that I generated with fpdf, and I needed to add on a variable amount of PDFs to it.

So I already had an fpdf object and page set up ( And I used fpdi to import the files ( FDPI is added by extending the PDF class:

class PDF extends FPDI


    $pdffile = "Filename.pdf";
    $pagecount = $pdf->setSourceFile($pdffile);  
    for($i=0; $i<$pagecount; $i++){
        $tplidx = $pdf->importPage($i+1, '/MediaBox');
        $pdf->useTemplate($tplidx, 10, 10, 200); 

This basically makes each pdf into an image to put into your other pdf. It worked amazingly well for what I needed it for.

Source: stackoverflow