In my previous post fetch pdf form fields i have discussed about to fetch the editable form field in a pdf . Now if you wants to fill that pdf with dynamic data then i am going to discuss a function which can do this job for you.
you just need a class Pdfparser

class Pdfparser {
public 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($val) . ')>>';
}
}
$data.="] \n/F (" . $file . ") /ID [ <" . md5(time()) . ">\n] >>" .
" \n>> \nendobj\ntrailer\n" .
"<<\n/Root 1 0 R \n\n>>\n%%EOF\n";
return $data;
}
public function createXFDF($file, $info, $enc = 'UTF-8') {
$data = '<?xml version="1.0" encoding="' . $enc . '"?>' . "\n" .
'<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">' . "\n" .
'<fields>' . "\n";
foreach ($info as $field => $val) {
$data.='<field name="' . $field . '">' . "\n";
if (is_array($val)) {
foreach ($val as $opt)
$data.='<value>' . htmlentities($opt) . '</value>' . "\n";
} else {
$data.='<value>' . htmlentities($val) . '</value>' . "\n";
}
$data.='</field>' . "\n";
}
$data.='</fields>' . "\n" .
'<ids original="' . md5($file) . '" modified="' . time() . '" />' . "\n" .
'<f href="' . $file . '" />' . "\n" .
'</xfdf>' . "\n";
return $data;
}

Now you can call these functions to fill pdf fields . Use this function for this task

function Fillpdfdata() {
$min = date('i') % 25;
$fdf_file = '/uploads/temp/posted-' . $min . '.fdf';
// create directory if it is not exists
$tmp_dir = '/uploads/temp';
if (!is_dir($tmp_dir)) {
mkdir($tmp_dir, 0777);
}
$pdf_to_fill = '/uploads/forms/test.pdf';
$datatofill=array('field name'=>'field value');
// get form fields as defined here  http://codingbin.com/fetch-pdf-form-fields-with-php/
$fdf = new Pdfparser;
$fdf = $fdf->createFDF($pdf_file, $datatofill);
// Create a file for later use
if ($fp = fopen($fdf_file, 'w')) {
fwrite($fp, $fdf);
$CREATED = TRUE;
} else {
echo 'Unable to create file: ' . $pdf_to_fill . '
';
$CREATED = FALSE;
}
fclose($fp);
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="test.pdf"');
passthru("pdftk " . $pdf_to_fill . " fill_form " . $fdf_file . " output - ");
unlink($fdf_file);
exit;
}

this function will download the filled pdf .

http://codingbin.com/wp-content/uploads/2015/12/Untitled-1-copy5.jpghttp://codingbin.com/wp-content/uploads/2015/12/Untitled-1-copy5-150x150.jpgdevidphpfill pdf,pdf formsIn my previous post fetch pdf form fields i have discussed about to fetch the editable form field in a pdf . Now if you wants to fill that pdf with dynamic data then i am going to discuss a function which can do this job for you. you just need...coding, php, wordpress, yii, cakephp, and  jquery

Are you want to get implementation help, or modify or extend the functionality of this script? Submit paid service request