Modify PDF Using FPDF/FPDI library

Posted: March 15, 2011 in Stay Hungry Stay Foolish..

I searched a lot and did lot of RND on specification of PDF and to get the PDF modified by my own way, but was unsuccessfull in doing that.. By the side i was into the looking for any existing library… where I found FPDI the associative library to FPDF to modify the PDF. As I was in the need to paste few Images in PDF  at certain fixed coordinates.. I have used it the library in that way….

Below is the action file with the help of which I was able to get What I needed..
<?php
require_once('fpdf.php');
require_once('fpdi.php');

$pdf =& new FPDI();
$pdf->AddPage();

//Set the source PDF file
$pagecount = $pdf->setSourceFile(“Tally_PO.pdf”);

//Import the first page of the file
$tppl = $pdf->importPage(1);

//Use this page as template
// use the imported page and place it at point 20,30 with a width of 170 mm
$pdf->useTemplate($tppl, -10, 20, 210);

#Print Hello World at the bottom of the page

//Select Arial italic 8
$pdf->SetFont(‘Arial’,”,8);
$pdf->SetTextColor(0,0,0);
$pdf->SetXY(90, 160);

$pdf->Image(‘om12iii.jpg’,45,220,15,10);
$pdf->Image(‘Om.jpg’,65,220,15,10);
$pdf->Image(‘think.jpg’,80,220,15,10);
$pdf->Image(‘Om.jpg’,140,240,15,10);

//$pdf->Write(0, “Hello World”);

$pdf->Output(“modified_pdf.pdf”, “F”);
?>

 

You can download the fpdf lib from: FPDF

And Download the Assocoative FPDI lib from: FPDI

Your Suggestions are Most Welcome….

Advertisements
Comments
  1. With this code u only take the page u want and add the image but what happened with the rest of the pdf?

  2. […] like there is an extension for fpdf. And here is a blog post about howto modify an existing pdf: https://pranavom.wordpress.com/2011/03/15/modify-pdf-using-fpdffpdi-library/ Tagged: .pdffpdffpdiPHP5questions /* * * CONFIGURATION VARIABLES: EDIT BEFORE […]

  3. sandeep says:

    thanks for posting this code. but when i used this code ..a black colored PDF is created. also i didn’t seen my previous PDF and the images which i wanted to insert to existing PDF.
    if anybody have any idea whats happing. please tell me. thanks…….

  4. Ron Knee says:

    This helped me. Thanks!

  5. […] I have interactive PDF form and my requirement is to insert an image into pdf at specific position. To insert an image into pdf I have used the library fpdf and fpdi as described in this post or here. […]

  6. […] It seems like there is an progression for fpdf. And here is a blog post about howto cgange an existent pdf: https://pranavom.wordpress.com/2011/03/15/modify-pdf-using-fpdffpdi-library/ […]

  7. Pradeep Singh says:

    How can i rotate the source pdf file before editing

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s