©
This document uses PHP Chinese website manual Release
[#1] bea dot el dot tea at gmail dot com [2011-08-17 09:01:19]
If you can't get the php_fdf.dll working in PHP 5.3 on Windows, one possible work around is to use the activeX version from the "FDF Toolkit for Windows" from the Adobe website. Here is part of a class I built for one of my projects.
<?php
class FDF{
public $NormalAP = 0;
public $RolloverAP = 1;
public $DownAP = 2;
protected $fdf;
public function __construct(){
$com = new COM('FdfApp.FdfApp');
$this->fdf = $com->FDFCreate();
}
public function setFile($fileName){
$this->fdf->FDFSetFile(str_replace(' ', '%20', $fileName));
}
public function setValue($name, $value){
$this->fdf->FDFSetValue($name, $value, true);
}
public function setAP($field, $whichFace, $fileName, $pageNumber){
$this->fdf->FDFSetAP($field, $whichFace, $fileName, $pageNumber);
}
public function savetoFile($saveFileName){
$this->fdf->FDFSavetoFile($saveFileName);
}
public function close(){
$this->fdf->FDFclose();
}
}
?>
[#2] info at theindigoworks dot com [2007-07-12 08:49:45]
re. g8z at yahoo dot com 18-Oct-2004 06:46
I think there is a line missing in
foreach ($keys as $key => $value)
{
$key = addcslashes($key, "\n\r\t\\()");
$fdf .= "<< /T ($key) /V /$value >> \n";
}
I have changed it to read
$key = addcslashes($key, "\n\r\t\\()");
$value = addcslashes($value, "\n\r\t\\()");
$fdf .= "<< /T ($key) /V /$value >> \n";
Now all the check boxes and radio buttons are populated, not just the last one in the form as was happening before.
[#3] wesley_grant at yahoo dot com [2006-01-11 15:37:20]
Changing the
session.cache_limiter
directive in the php.ini file to 'private'
seems to resolve the issue with sending fdf data and session headers at the same time to Internet Explorer.
[#4] bmount at livid dot us [2005-10-19 08:05:03]
For those of you struggling with FDF in Internet Explorer, here is your solution:
DO NOT INITIALIZE A SESSION ON THE PAGE THAT GENERATES AND OUTPUTS FDF DATA.
This will fix the page not found error.
[#5] [2005-05-03 13:08:09]
Use "Yes" instead of "On" to populate checkboxes.
[#6] g8z at yahoo dot com [2004-10-17 23:46:02]
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);
?>
[#7] sid at accesspdf dot com [2004-10-07 11:09:23]
Basic FDF data is easy to create using native PHP; you don't need Adobe's FDF Toolkit. I wrote a function for this purpose called forge_fdf(). You can download it from:
http://www.pdfhacks.com/forge_fdf/
I created it for my book, PDF Hacks. An example of forge_fdf() in action can be viewed online:
http://pdfhacks.com/form_session/form_session-1.1/
Download the full code for this online example from:
http://pdfhacks.com/form_session/
Note how the PDF form data is submitted back to the server via POST rather than FDF. No need to parse FDF.
Cheers-
Sid Steward
[#8] m1tk4 at hotmail dot com [2004-06-30 22:34:22]
If you want to add FDF support without rebuilding your RedHat EL3 / Fedora PHP RPMs, see instructions at http://phprpms.sourceforge.net/fdf
[#9] software at yvanrodrigues dot com [2004-03-25 14:16:57]
Do not use version 6 of the fdftk.dll (windows) with PHP4.3.4, use the one that comes with PHP.
If you use the newer DLL fdf_create will not return a valid handle.
[#10] fleischer at mail dot com [2003-12-18 07:40:44]
[#11] mirage at rateaprof dot com [2003-05-08 05:33:40]
If you get the new fdftkv5.tar.gz from adobe's site (per the link above), you'll get some totally new spacing and capitalization of files. To make the current 4.3.1 configure, you need to do a few things.
untar fdftkv5.tar.gz into /usr/local
cd /usr/local
#for ease of use
ln -s FDFToolkit\ for\ UNIX fdf
cd fdf
ln -s Headers\ And\ Libraries HeadersAndLibraries
#may need to modify the following for your OS
ln -s LINUX linux
cd linux/C
ln -s LIBFDFTK.SO libfdftk.so
cd ..
cd ..
ln -s Headers headers
cd headers
ln -s FDFTK.H fdftk.h
And that should get you going... and to whoever is maintaining the configure script, please be aware there are changes in the FDF Toolkit.
[#12] Teemu [2003-03-05 06:17:43]
Maybe you have to use Header-function that your browser will regonize xfdf-file. Like this:
Header( "Content-type: application/vnd.adobe.xfdf");
[#13] jeff at cowart dot net [2003-01-19 20:06:33]
I have tried to use the scripts above by adam and Toppi and I have been unable to get them to work unless I save the generated fdf file and then open it manually in acrobat.
[#14] Toppi at i-Mehl dot De [2002-11-26 12:18:03]
I tried a lot with FDF -> PDF and merging these documents...
in my opinon xfdf is more handy than fdf... for those who'd like to try: feel free to use this little function to generate an xfdf document from an array.
ToPPi
function array2xfdf($xfdf_data, $pdf_file) {
// Creates an XFDF File from a 2 dimensional
// Array Format: "array ("key1" => "content1", "key2" => "content2");
$xfdf = "
<?phpxml version='1.0' encoding='UTF-8'?>
\n";
$xfdf .= "<xfdf xmlns='http://ns.adobe.com/xfdf/' xml:space='preserve'>\n";
$xfdf .= "<fields>\n";
// Loop -> Array to XFDF Data
foreach ($xfdf_data as $key => $val) {
$xfdf .= "<field name='".$key."'>\n";
$xfdf .= "<value>".$val."</value>\n";
$xfdf .= "</field>\n";
};
// XFDF "Footer"
$xfdf .= "</fields>";
$xfdf .= "<f href='".$pdf_file."'/>";
$xfdf .= "</xfdf>";
return $xfdf;
}
[#15] mitka at actdev.com [2002-10-21 16:24:40]
IMPORTANT:
If you handled the FDF POSTs via $HTTP_RAW_POST_DATA as in user contributed scripts above, it's good to know that once you decide to rebuild PHP with FDFToolkit support, $HTTP_RAW_POST_DATA will be undefined.
Good news - $HTTP_FDF_DATA _will_ be defined instead. (Look at the example above).To get the user contributed scripts working in both plain PHP and PHP+FDFToolkit use
$HTTP_RAW_POST_DATA . $HTTP_FDF_DATA
where $HTTP_RAW_POST_DATA mentioned.
Dimitri Tarassenko
[#16] adam at andemyte dot com [2002-08-02 11:30:18]
[#17] noah at NOSPAMbrandfidelity dot com [2002-03-08 20:26:25]
function parse($file) {
if (!preg_match_all("/<<\s*\/V([^>]*)>>/x",
$file,$out,PREG_SET_ORDER))
return;
for ($i=0;$i<count($out);$i++) {
$pattern = "<<.*/V\s*(.*)\s*/T\s*(.*)\s*>>";
$thing = $out[$i][1];
if (eregi($pattern,$out[$i][0],$regs)) {
$key = $regs[2];
$val = $regs[1];
$key = preg_replace("/^\s*\(/","",$key);
$key = preg_replace("/\)$/","",$key);
$key = preg_replace("/\\\/","",$key);
$val = preg_replace("/^\s*\(/","",$val);
$val = preg_replace("/\)$/","",$val);
$matches[$key] = $val;
}
}
return $matches;
}
[#18] gregDELETETHIS at laundrymat dot tv [2001-12-21 15:06:07]
Here is an easy script to output fdf data to the browser without using the fdf toolkit or creating an actual fdf file on the server.
By the way acrobat is very picky about line breaks so you must leave the "\n" in the script. The script reads the variables posted to it from a form use POST and creates a fdf file from them. The field names posted to this script must match the field names in the pdf. Acrobat will ignore any that don't match.
<?php
//path to pdf file
$url="http://www.some_url.com/form.pdf";
$values=$HTTP_POST_VARS;
$fdfdata = "%FDF-1.2\n%????\n";
$fdfdata .= "1 0 obj \n<< /FDF ";
$fdfdata .= "<< /Fields [\n";
//loop that adds the field names and values
foreach($values as $key=>$val)
{
$fdfdata.="<< /V ($val)/T ($key) >> ";
}
$fdfdata .= "]\n";
$fdfdata .= "/F ($url) >>";
$fdfdata .= ">>\nendobj\ntrailer\n<<\n/Root 1 0 R\n>>\n";
$fdfdata .= "%%EOF";
header ("Content-Type: application/vnd.fdf");
print $fdfdata;
?>
You can use javascript in the pdf to read the values from a GET method posted directly to the pdf. you can see both methods here: http://laundrymat.tv/pdf/
[#19] joe at koontz dot net [2000-04-28 16:42:01]
The simplest thing to do is get the FDF data from $HTTP_RAW_POST_DATA. (unless you have the server library installed none of the fdf data gets parsed!) This is typical of what you get:
%FDF-1.2
1 0 obj
<<
/FDF << /Fields [ << /V (0)/T (amount0)>> << /V (0)/T (amount1)>> << /V (0)/T (amount2)>>
<< /V (0)/T (amount3)>> << /V (0)/T (amount4)>> << /V (0)/T (amount5)>>
<< /V (0)/T (amount6)>> << /V (0)/T (amount7)>> << /V (0)/T (amount8)>>
<< /V (0)/T (amount9)>> << /V /0102 /T (chase_bk)>> << /V (0)/T (count)>>
<< /V (0)/T (invtotal)>> << /V (12/21/2000)/T (sent_ap)>> << /V /Off /T (spec_hand)>>
<< /V (041232)/T (transit_no)>> << /V (THIS FORM IS NOT COMPLETE!!!)/T (X)>>
]
/F (http://x.com/forms/AA00390q.pdf)>>
>>
endobj
trailer
<<
/Root 1 0 R
>>
%%EOF
kill everything before the [ and then parse it down into key value pairs.
I wrote this to create an FDF, make sure you do a
header("Content-type: application/vnd.fdf");
before you echo the returned value to the user.
<?php
function FDFput($FDFpage){
$A = "%FDF-1.2\n1 0 obj\n<< \n/FDF << /Fields [ \n";
$C = " ] \n" ;
if ($FDFpage>"" ) {$C .=" /F ($FDFpage)>>\n";}
$C .= ">>\n>> \nendobj\ntrailer\n\n<</Root 1 0 R>>\n%%EOF\n";
$B = "";
reset($FDFData);
while (list($key, $val) = each($FDFData))
{
if (strlen(trim($val)) > 0 && is_string($key))
{
$B .= "<</T ($key) /V (". $val . ")>>\n";
//echo "<</T ($key) /V (". $val . ")>>\n";
}
}
return $A.$B.$C;
}
?>
It ain't perfect - but it works. (I use HTML for posting to the server, FDF to the browser)
joe