Menu

Import external pdf file with TCPDF...

Help
saprile
2010-09-15
2012-10-09
  • saprile

    saprile - 2010-09-15

    Hello, I have a question with using TCPDF. I need to import one external pdf
    file into the new pdf file created with TCPDF. My aim is to insert a watermark
    in the new one. Is this possible with TCPDF?

    Thanks

     
  • saprile

    saprile - 2010-09-15

    Yes with FPDI, not TCPDF, but with FPDI is not possible insert a background
    image.

     
  • Jan Slabon

    Jan Slabon - 2010-09-15

    Could you be more specific? Why should it be impossible to use a background
    image with FPDI?

     
  • saprile

    saprile - 2010-09-15

    I have not found any FPDI manual, what is the command to insert a background
    image with FPDI? Can you help me?

     
  • Jan Slabon

    Jan Slabon - 2010-09-15

    How would you insert a background image with TCPDF?

     
  • saprile

    saprile - 2010-09-15

    // Extend the TCPDF class to create custom Header and Footer
    class MYPDF extends TCPDF {
    //Page header
    public function Header() {
    // full background image
    // store current auto-page-break status
    $bMargin = $this->getBreakMargin();
    $auto_page_break = $this->AutoPageBreak;
    $this->SetAutoPageBreak(false, 0);
    //$img_file = K_PATH_IMAGES.'image_demo.jpg';
    $img_file = '../../upload/img/utente.jpg';
    $this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false,
    false, 0);
    // restore auto-page-break status
    $this->SetAutoPageBreak($auto_page_break, $bMargin);
    }
    }

    $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true,
    'UTF-8', false);

    $pdf->addPage();
    $pdf->Output('new.pdf', 'I');

     
  • Jan Slabon

    Jan Slabon - 2010-09-15

    so... simply extends FPDI instead of TCPDF and you should have the same
    result. It's simply PHP...

     
  • Lubos Dz

    Lubos Dz - 2011-01-20

    There is no such a command.

    FPDI is a TCPDF class wrapper, which can extend TCPDF class ad add extra
    features, such as importing pages from another binary PDF file. That means,
    you would create class like FPDI_TCPDF extends TCPDF, and then use FPDI
    command to parse existing PDF file and import desired page into it.

    Yet, you can normally insert images in such a class, e.g.
    FPDI_TCPDF->image(params...) just like normal TCPDF.

    I wonder, if Nicola would add such a feature for importing parsed external
    files. Solution actually already exists (FPDI) and I use it, but it is kind of
    pain to rename classes with each TCPDF upgrade:-)

    Cheers
    Lubos

     
  • Jan Slabon

    Jan Slabon - 2011-01-20

    You don't have to rename anything... just initiate FPDI instead of TCPDF and
    everything will work as before... but you have the new methods for importing
    existing pages... There's no need to touch at least one line if you update
    TCPDF.

    Cheers!
    Jan

     
  • Ori Idan (Helicon technologies)

    I tried using FPDI to import a PDF file to TCPDF and got empty document.

    I used the following code:

    require_once('tcpdf/tcpdf.php');
    include('fpdi/fpdi.php');

    $pdf = new FPDI
    $pdf->setInputFile($fname);
    $pdf->importPage(1);
    $pdf->Output("test.pdf", D);

     

Log in to post a comment.

MongoDB Logo MongoDB