note 46624 added to ref.fdf
| From: | g8z at yahoo dot com | Date: | Mon, 18 Oct 2004 06:46:02 +0000 |
| Subject: | note 46624 added to ref.fdf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78714@lists.php.net to get a copy of this message | ||
This is for users who are looking for a way to merge HTML form data with a PDF Form, then output the
PDF Form with data populated in it, to a web browser.
This is a pure PHP solution which does NOT require the FDF toolkit. Contributed by www.TUFaT.com
<?php
// the full http path to the PDF form
$form = 'http://my_domain.com/my_pdf_form.pdf';
function create_fdf ($pdffile, $strings, $keys)
{
$fdf = "%FDF-1.2\n%\n";
$fdf .= "1 0 obj \n<< /FDF << /Fields [\n";
foreach ($strings as $key => $value)
{
$key = addcslashes($key, "\n\r\t\\()");
$value = addcslashes($value, "\n\r\t\\()");
$fdf .= "<< /T ($key) /V ($value) >> \n";
}
foreach ($keys as $key => $value)
{
$key = addcslashes($key, "\n\r\t\\()");
$fdf .= "<< /T ($key) /V /$value >> \n";
}
$fdf .= "]\n/F ($pdffile) >>";
$fdf .= ">>\nendobj\ntrailer\n<<\n";
$fdf .= "/Root 1 0 R \n\n>>\n";
$fdf .= "%%EOF";
return $fdf;
}
// Fill in text fields
$strings = array(
'date' => '10/17/2004',
'full_name' => 'Joe Doe',
'phone_num' => '123-4567',
'company' => 'ACME Widgets',
'amount' => 'USD 100.00'
);
// Fill in check boxes/radio buttons
$keys = array('
gender' => 'male',//radio button
'is_adult' => 'Off',//checkbox
'urgent' => 'On'//checkbox
);
// Output the PDF form, with form data filled-in
header('Content-type: application/vnd.fdf');
echo create_fdf($form, $strings, $keys);
?>
----
Manual Page -- http://www.php.net/manual/en/ref.fdf.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46624
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46624&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46624&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46624&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46624&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46624&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46624&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46624&report=yes
Search -- http://master.php.net/manage/user-notes.php