PDF Form Filling with FPDF

14.8k Views Asked by At

There is a scripts section at fpdf.org that has an example for filling PDFs dynamically. Here is the script.

<?php

/***************************
  Sample using a PHP array
****************************/

require('fpdm.php');

$fields = array(
    'name'    => 'My name',
    'address' => 'My address',
    'city'    => 'My city',
    'phone'   => 'My phone number'
);

$pdf = new FPDM('template.pdf');
$pdf->Load($fields, false); // second parameter: false if field values are in ISO-8859-1, true if UTF-8
$pdf->Merge();
$pdf->Output();
?>

First - they reference fpdm.php - i assume that is a mistake, and changed it to fpdf.php, as well as the class reference - so that isn't the source of my error. When I change all that and set up a test - i get an error saying that the "orientation is wrong".

Every other fpdf example has you entering paramaters into the function to set orientation (P or L) as well as size (A4) etc. This one does not. Has anyone messed with this example and gotten it to work? We're using an HTML form on a doctors website to take info and then merging it with their actual forms and outputting them as a PDF for their charts - so a script like this where i can load the whole record in an array and pop them in the fields on the PDF would be fantastic.... if it worked :)

3

There are 3 best solutions below

0
On

fpdm.php is actually something you have to download right underneath the example.

1
On

The fpdm.php is the right one. You don't have the option to enter the parameters like in fpdf because this library use the template pdf file that you created. It's only fill the template form for you using the array of fields in php code (see the ex-array.php file) or using the fields form (ex-fdf.php). Notice that if you open the output pdf file in browser, the filled information will not show up, you have to open it in a PDF viewer (Acrobat Reader...) to see the result.

0
On

i found something that might help you out.

Try FPDI

With FPDI you can use .pdf as a kind of template an handle it with FPDF als an Image.