Is there a way to post data INTO a PDF using php.
In other words do a database call then take those fields and merge them into an already existing PDF with blank fields.
I'm using this code and it's not working i'm getting an error that says "expected a dict object"
The fdf file that it generates is only 1kb, so somewhere there is corruption. The code below is supposed to work.
<?
$file = "/var/www/html/tmp/mccs_ap
p.pdf";
$data['text1']= "$5,000.00";
$data['text2']= "Dr. John Doe";
$data['text3']= "800-555-1212";
$data['text4']= "Dan";
$data['text5']= "Smith";
// I wanted to add the date to the submissions
//$data['Text1']=date('Y-m
-d H:i:s');
function createFDF($file,$info){
$data="%FDF-1.2\n%??n1 0 obj\n<< \n/FDF << /Fields [ ";
foreach($info as $field => $val){
if(is_array($val)){
$data.='<</T('.$field.')/V
[';
foreach($val as $opt)
$data.='('.trim($opt).')';
$data.=']>>';
}else{
$data.='<</T('.$field.')/V
('.trim($v
al).')>>';
}
}
$data.="] \n/F (".$file.") /ID [ <".md5(time()).">\n] >>".
" \n>> \nendobj\ntrailer\n".
"<<\n/Root 1 0 R \n\n>>\n%%EOF\n";
return $data;
}
// file name will be <the current timestamp>.fdf
$fdf_file=time().'.fdf';
// the directory to write the result in
$fdf_dir=dirname(__FILE__)
.'/results
';
// need to know what file the data will go into
$pdf_doc="/var/www/html/tm
p/mccs_app
.pdf";
// generate the file content
$fdf_data=createFDF($pdf_d
oc,$data);
// this is where you'd do any custom handling of the data
// if you wanted to put it in a database, email the
// FDF data, push ti back to the user with a header() call, etc.
// write the file out
if($fp=fopen($fdf_dir.'/'.
$fdf_file,
'w')){
fwrite($fp,$fdf_data,strle
n($fdf_dat
a));
echo $fdf_file,' written successfully.';
} else {
die('Unable to create file: '.$fdf_dir.'/'.$fdf_file);
}
fclose($fp);
?>
Start Free Trial