note 38370 added to ref.fdf
| From: | fleischer at mail dot com | Date: | Thu, 18 Dec 2003 12:40:44 +0000 |
| Subject: | note 38370 added to ref.fdf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-62172@lists.php.net to get a copy of this message | ||
The code suggested by greg@... and adam@... is extremely helpful, but I've found out (the hard
way) that unclosed parentheses within strings contained in the input array ($values in greg's
code or $pdf_data in adam's) will cause Acrobat to issue an error to the effect that the file
is corrupted. In other words, if there are strings such as "a) my first point; b) my second
point" in the input array, the resulting PDF/FDF file will be considered corrupted by Acrobat.
This apparently happens because all the field names in the structure of an FDF file are enclosed in
parentheses.
The solution I've devised is to escape all opening and closing parentheses with a backslash,
which in turn means you need to escape all backslashes. The code below does all that.
Erik
---------------
function output_fdf ($pdf_file, $pdf_data)
{
$fdf = "%FDF-1.2\n%\n";
$fdf .= "1 0 obj \n<< /FDF ";
$fdf .= "<< /Fields [\n";
$search = array('\\', '(', ')');
$replace = array('\\\\', '\(', '\)');
foreach ($pdf_data as $key => $val)
{
$clean_key = str_replace($search, $replace, $key);
$clean_val = str_replace($search, $replace, $val);
$fdf .= "<< /V ($clean_val)/T ($clean_key) >> \n";
}
$fdf .= "]\n/F ($pdf_file) >>";
$fdf .= ">>\nendobj\ntrailer\n<<\n";
$fdf .= "/Root 1 0 R \n\n>>\n";
$fdf .= "%%EOF";
return $fdf;
}
----
Manual Page -- http://www.php.net/manual/en/ref.fdf.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38370
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38370&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38370&report=yes
Search -- http://master.php.net/manage/user-notes.php