Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tcpdf - start with existing PDF document

Tags:

php

pdf

tcpdf

I have several PDF templates that I would like to load and modify and output using tcpdf.

Is it possible to load an existing PDF and use it as a starting point in tcpdf?

like image 269
Marko Avatar asked Sep 13 '09 21:09

Marko


2 Answers

You want to use FPDI.

There's some example code here.

like image 200
timdev Avatar answered Sep 23 '22 22:09

timdev


I have tried the free version of FPDI but does not support PDF version 1.5 or higher.

If someone else is looking for a free solution I have used TCPDI. You can find it on github https://github.com/pauln/tcpdi If you are using composer, you can find some fork for composer too. Just search tcpdi on github.

Once you add it to your project, the code is quite simple. It is an extension of TCPDF so all your previous code keep working

This is a snippet from my code. I used it to save a copy of the privacy policy (a static pdf) with the user name and agreement date on each page footer.

// Create new PDF document $pdf = new TCPDI(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); ... // Add the pages from the source file. $pagecount = $pdf->setSourceFile($policyPdfPath); for ($i = 1; $i <= $pagecount; $i++) {     $tplidx = $pdf->importPage($i);     $pdf->AddPage();     $pdf->useTemplate($tplidx);     // Add agreement text in document footer     $pdf->SetXY(15,282);     $pdf->Cell(180, 5, "Documento approvato da {$fullName} il {$date}", 0, 0, 'C'); } // Send PDF on output $pdf->Output(FOLDER_PATH . DIRECTORY_SEPARATOR . "{$userId}.pdf", 'F'); 
like image 37
AbdulkadirFaghi Avatar answered Sep 22 '22 22:09

AbdulkadirFaghi