How to get the exact modified PDF using FPDF/FPDI?
Asked Answered
E

2

8

i have a task to modify the PDF and add an image into it, for which I Have used the FPDF and FPDI libraries.. whose action code is given below:

<?php
require_once('fpdf.php');
require_once('fpdi.php');

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

//Set the source PDF file
$pagecount = $pdf->setSourceFile("Completed.pdf");

//Import the first page of the file
$tpl = $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($tpl, 20, 30, 170);

#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->Rotate(90);
$pdf->Image('think.jpg',120,240,20,20);
$pdf->Image('think.jpg',120,260,20,20);
//$pdf->Write(0, "Hello World");

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

But When I get the Modified pdf I can get very distorted modified pdf... whose screen shot is given below:

enter image description here

The Original Document is as given below:

enter image description here

Hence Could anyone help me in retrieveing the correct Modified PDF using the same code/ modified code..?

Enticement answered 10/3, 2011 at 6:14 Comment(6)
@Gordan Could U Help Me In this?Enticement
@Pekka Could U Help me In this?Enticement
Faced the same problem recently, seems to be a bug within fpdf when saving to a file - dowloading the same generated pdf works. I ended up exporting to an xls instead of a pdf.Malefaction
it seems like fonts are damaged, do you tried to compare files binary?Teethe
@Malefaction @Teethe Thanks For the Focus for its being a BUG.. But Unfortunately I am in the need of getting the PDF instead...Enticement
@OMTheEternity Please let me know one thing how i download the both library files i have also work same task "I want to add some data in existing pdf file". I m trying to run your code but library required.So please give me the download link of both library. Thanks :)Michail
E
2

its fpdf_tpl.php file needed to be updated with new download

Enticement answered 10/3, 2011 at 11:33 Comment(0)
M
0

http://www.tcpdf.org/ Use TCPDF its good ...

Monochromatism answered 10/3, 2011 at 9:37 Comment(1)
Will it Modify My Existing PDF and Write the Image in the required Position?Enticement

© 2022 - 2024 — McMap. All rights reserved.