Writing / Drawing on a PDF Template Document in PHP

I would like to be able to write / overlay text on top of an existing pdf document using PHP. I hope you have a pdf document that can act as a template and fill in the blanks by opening the template document, overlaying the appropriate text and showing the result as a new document. A template document is a single page, so page merging / manipulation is not required.

Are there any free libraries that can do this? Wherever I look? Most of my queries seem to be related to document merging / adding pages, instead of overlaying content on top of an existing page.

Thank.

* EDIT: Here's what I did: 1. Download FPDF 2. Download FPDI + FPDF_TPL from

http://www.setasign.de/products/pdf-php-solutions/fpdi/downloads/

Here is a sample code for any future wanderers (adapted from samples at www.setasign.de):

<?php include('fpdf.php'); include('fpdi.php'); // initiate FPDI $pdf =& new FPDI(); // add a page $pdf->AddPage(); // set the sourcefile $pdf->setSourceFile('templatedoc.pdf'); // import page 1 $tplIdx = $pdf->importPage(1); // use the imported page as the template $pdf->useTemplate($tplIdx, 0, 0); // now write some text above the imported page $pdf->SetFont('Arial'); $pdf->SetTextColor(255,0,0); $pdf->SetXY(25, 25); $pdf->Write(0, "This is just a simple text"); $pdf->Output('newpdf.pdf', 'D'); ?> 
+44
php pdf
Nov 28 '10 at 21:53
source share
3 answers

Look at the FPDI Library add to FPDF for template annotation.

It can also connect to TCPDF , another popular PHP PDF library. The existing PDF file is used as the base of the page, and not empty, after which the procedures are the same as the usual creation of PDF.

+19
Nov 28 2018-10-28
source share

You probably want to use PDF forms for what you want to do. To fill out these children, you can use the FDF method described here: Using HTML forms to fill in PDF fields using PHP and FDF .
Actually, there is another good SO post about filling out PDF forms: Filling PDF forms with PHP .

+4
Nov 28 '10 at 22:00
source share

If you want to use the PDF library to write to a document, positioning is time consuming and boring. The deck is useful for such a task: https://github.com/applicius/dhek/releases .

The JSON mapping is determined by the PDF page / coordinates, so you can write using the PDF API you prefer.

+1
May 28 '14 at 7:53
source share



All Articles