Monday, July 5, 2010

PHP Script accept query string data and place onto PDF form

require_once('fpdf.php');
require_once('fpdi.php');
$pdf = new FPDI();
$pdf->AddPage();
$pdf->setSourceFile('../pdfdoc\MedSolMRICTheadneck.pdf');
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 10, 10, 200);

$pdf->SetFont('Arial','B',10);
$pdf->SetTextColor(0,0,255);
$pdf->SetXY(56, 50);
$pdf->Write(0, $_GET['lastname'].'---'.$_GET['firstname'].'---'.$_GET['dob']);

$pdf->Output();
?>

Notes:
-The $_GET[] array names are in quotes to make WAMP happy and match the query string names the the javascript bookmarklet that sent the query
-The main work in writing this is finding the XY coordinates in the third to last line
-Copy and paste the 4 line block for each data entry point on the form, each with its own XY coordinates
-Note the color 0,0,255 (blue). Other useful colors: 0,0,0 - black and 255,0,0 - red.
-Note the 'B' parameter in font for bold: helpful when filling out forms.
-Note the source file path with the backslashes again to make WAMP happy.

So, big picture: You've invoked a bookmarklet to navigate from a website with data to a PHP script on WAMP which pulls up a PDF document in your localhost directory tree and inserts the data on the form. Now you run your AutoHotKey script to print or fax it.

No comments:

Post a Comment