Jump to content

Product attachment PDF customisation


rajaramprobytes

Recommended Posts

Hi 

 

My client asking for product attachment "custom PDF  "

 

Every time upload the pdf for product in attachment .... that time automatically header and footer page added in dynamically in pdf.

 

I have PHP code but i can't able to implement this in AdminAttachmentsController.php

 

Please help me 

 

 

 

It's PHP Code 

-----------------------------------

<?php
require_once('FPDF/fpdf.php');
require_once('FPDI/fpdi.php');
 
 
// define some files to concatenate
$files = array(
    'header.pdf',
    'innerpage.pdf',
    'footer.pdf'
);
 
// initiate FPDI
$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);
 
        $pdf->SetFont('Helvetica');
        $pdf->SetXY(5, 5);
        $pdf->Write(8, 'Its developed by rajaram');
    }
}
 
// Output the new PDF
//$pdf->Output(); 
$pdf->Output("sampleUpdated.pdf", 'F');
Edited by rajaramprobytes (see edit history)
Link to comment
Share on other sites

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...