[nycphp-talk] Adding Text To The Top of a PDF
David Mintz
dmintz at davidmintz.org
Tue Apr 18 09:48:13 EDT 2006
On Mon, 17 Apr 2006, Jeff Loiselle wrote:
> What's the best way to stab at adding two lines of text to the top of
> an existing PDF?
I think you want http://fpdi.setasign.de/index.php?p=home
I have a project in which I am going to need to open a PDF template and
fill in some data. Just to prove I could do it I created a document in
OpenOffice Writer with an empty rectangle drawn in a more or less
arbitrary position on the page, then saved it as a PDF called
test_pdf.pdf, then tried to use this class to open it, squirt some fresh
red ink right into the little box and save the new PDF to disk. It works.
<?php
define('FPDF_FONTPATH','../font/');
require('./fpdi.php');
$pdf= new fpdi();
$pdf->setTextColor(255,0,0);
$pagecount = $pdf->setSourceFile("./test_pdf.pdf");
$tplidx = $pdf->ImportPage(1);
$pdf->addPage();
$pdf->useTemplate($tplidx);
$pdf->SetXY(66,52);
$pdf->SetFont('helvetica','B',10);
$pdf->Cell(150,20,'new text written '.date('r'));
$pdf->Ln(5);
$pdf->SetX(66);
$pdf->Cell(150,20,'more text written soon thereafter');
$pdf->Output('./output.pdf','F');
$pdf->closeParsers();
echo "ok";
?>
---
David Mintz
http://davidmintz.org/
Amendment IV
The right of the people to be secure in their
persons, houses, papers, and effects, against
unreasonable searches and seizures, shall not be
violated, and no Warrants shall issue, but upon
probable cause, supported by Oath or affirmation,
and particularly describing the place to be
searched, and the persons or things to be seized.
More information about the talk
mailing list