Jump to content

Merge two different pdf's into a single one


JBravo

Recommended Posts

Hi all,

 

Thanks in advance for any help on this subject,

 

I've previously managed to work around with pdf's templates and php controller, in order to change contents and suit my needs, but I'm having a hard time to figure this one out:

 

I need to generate the delivery slip, in order that it contains two pages in the same pdf file instead of one. The only difference between them, is that one needs to display "original", and the other "duplicate"...

 

Thanks again for any light on this

 

 

Link to comment
Share on other sites

It is hard to print the delivery slip twice, because today its template is divided into several parts (header, footer, body).

 

I can imagine to do it using the M4 PDF Extensions module. It is very easy as it uses one page templates, so you can use the same code twice with <pagebreak> between the parts.

 

 

Link to comment
Share on other sites

  • 1 month later...

I just done something like this, a bit harder because i had to merge many differents files, some vertical and some landscape like.

 

you can use FPDF and FPDI (you have to include them).

adding 'original' and 'duplicate' should be easy, check the manual

 

to merge :

 

$file = array [filename1.pdf, filename2.pdf,...]

 

then :

$pdf = new FPDI();

// iterate through the files
foreach ($files AS $file) {
    // get the page count
    $pageCount = $pdf->setSourceFile($file);
    // iterate through all pages
    for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
        // import a page
        $templateId = $pdf->importPage($pageNo);
        // get the size of the imported page
        $size = $pdf->getTemplateSize($templateId);

        // create a page (landscape or portrait depending on the imported page size)
        if ($size['w'] > $size['h']) {
            $pdf->AddPage('L', array($size['w'], $size['h']));
        } else {
            $pdf->AddPage('P', array($size['w'], $size['h']));
        }

        // use the imported page
        $pdf->useTemplate($templateId);
    }
}


// output the pdf as a file (http://www.fpdf.org/en/doc/output.htm)
$pdf->Output(_PS_ADMIN_DIR_.'/../modules/yourmodulename/merged.pdf','F');


Edited by LauraPresta (see edit history)
Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...