0

I've been using the advice given in this question:

Merge FDF data into a PDF file using PHP

to determine how I can pre-populate a pdf form with data pulled from a database but not getting the data to file. I'm running php 5.3.15 on Mountain Lion and I'm using the following link to combine the pdf with the fdf on a table page that I'd like to allow the user to click and take them to a populated pdf file:

something.pdf#FDF=generatePdf.php

The generatePdf.php looks like this:

<?php
$pdf_form_url= "";
require_once('forge_fdf.php');

$fdf_data_names= array(); // none of these in this example
$fdf_data_strings= array(); // none of these in this example

$fdf_data_strings['form1[0].#subform[0].q1a_LastName'] = "Smith";
$fields_hidden= array();
$fields_readonly= array();

// set this to retry the previous state
$retry_b= false;

header( 'content-type: application/vnd.fdf' );

echo forge_fdf( $pdf_form_url,
    $fdf_data_strings, 
    $fdf_data_names,
    $fields_hidden,
    $fields_readonly );

?>

and the FDF file looks like this when I run it through the pdftk command line:

FieldType: Text
FieldName: form1[0].#subform[0].q1a_LastName[0]
FieldNameAlt: Enter Family Name
FieldFlags: 0
FieldJustification: Left
FieldMaxLength: 35

Still, when I run it the form doesn't auto populate. I've tried many variations including just using the q1a_LastName by itself and I still end up with an empty form. The forge_fdf.php is in the same directory.

Update: I've also attempted the conventional method outlined in the Merge FDF data into a PDF question that I've linked to using PHP, meaning I didn't just direct the user to a pdf file but also attmepted to have the user download the pdf. In that particular case, I would receive a message saying the pdf was empty. I've checked the created raw FDF file and it appears to be populating with data. In either case, I'm not getting what I need.

Community
  • 1
  • 1
boody
  • 17
  • 8

2 Answers2

0

After much trial and error I realized that the best way to autopopulate to a url linking to a pdf is to define the $pdf_form_url variable for the code above. This code will echo out the details of the fdf file. If you explicitly specify what the pdf url is, php and your browser will take the necessary steps to link you to a the pdf in your web browser with the embedded field information coming from the fdf output.

boody
  • 17
  • 8
  • So I stumbled upon this thread having the same problem, tried populating the the $pdf_form_url variable, and still couldn't get it to work. Can you perhaps shed some more light on the issue? – Mike T May 02 '14 at 01:10
0

So I stumbled upon this thread and couldn't get it to work even when I populate the $pdf_form_url variable. Here's my code:

require_once('forge_fdf.php');  

// leave this blank if we're associating the FDF w/ the PDF via URL
$pdf_form_url= "http://test.pdf";
// $pdf_form_url= "";


// default data; these two arrays must ultimately list all of the fields
// you desire to alter, even if you just want to set the 'hidden' flag;
//
//
$fdf_data_names= array(); // none of these in this example
$fdf_data_strings= array(); // none of these in this example
$fdf_data_strings['Address, Row 1']="XXXX Balboa Arms Drive #XXX, San Diego CA 01234";

$fields_hidden= array();
$fields_readonly= array();

// set this to retry the previous state
$retry_b= false;

header( 'content-type: application/vnd.fdf' );

echo forge_fdf( $pdf_form_url,
        $fdf_data_strings, 
        $fdf_data_names,
        $fields_hidden,
        $fields_readonly );

And here's the form field I want to update using pdftk dump_data_fields:

FieldType: Text
FieldName: Address, Row 1
FieldNameAlt: (Address, &lt;Row 1&gt;)
FieldFlags: 0
FieldJustification: Center
Mike T
  • 359
  • 7
  • 17
  • The field name you are using looks a little off. Can you link to the pdf somewhere? From what I've seen, the fields in a PDF should follow a DOM-like structure. – boody May 03 '14 at 23:30
  • It probably does have something to do with the naming convention, but I did not move forward with the project, and someone with more experience was probably able to figure it out. Thank you though! – Mike T May 04 '14 at 07:39