Last updated January 4, 2013. Created by Liam Morland on February 7, 2012.
Edited by wizonesolutions, haydeniv. Log in to edit this page.
Setting up a form for PDF filling
There are 3 steps to setting up a form with Fill PDF:
- Create the form which will supply the data, either a CCK content-type or a Webform.
- Map the data fields to the form controls in the PDF.
- Use a URL to merge the data into the PDF.
Create the form
To create the webform/content-type wherein users will enter data. Options:
- Use CCK
- Use Webform (see #374121: Webform Support)
Map the fields
To map the form to a PDF, do the following:
- Go to /admin/structure/fillpdf
- Upload a PDF template, a form mapping will be generated. Make sure the PDF document isn't encrypted. If it is encrypted and non copy-righted (typical of government PDFs), then try a decrypting tool like "Advanced PDF Password Recovery". If you upload an encrypted PDF, you will have empty PDFs when you attempt to download your submissions.
- When editing fields, note the following:
- "Label" is for your own use in identifying fields
- "PDF Key" is the field-name from the original PDF Form (such as text_field_1) and is the piece that maps the form-field to the PDF field
- "Value" is where you either enter static data to populate the field, or token-data to pull information form the users' forms. For example, if I created a CCK form with a text-field called field_first_name, then I would enter [field-field_first_name-raw] here. There is a list of tokens you can use at the bottom of that page.
Use a URL to merge the form data into the PDF
Once your user fills a form, they'll need a link to download their PDF. You can place this link in a block, .tpl.php, or anywhere. The link will need:
- The Form ID (you can see an example URL on your form's edit-page)
- the Node ID, and/or
- the webform's Node ID and optionally its Submission ID (defaults to latest submission if none provided)
Here are some ways to generate the link:
- Add the link manually in HTML or with Views field rewriting. Examples:
- Using a single node:
<a href="/fillpdf?fid=1&nid=2">PDF</a>. If the Clean URLs Drupal setting is not enabled, the URL will be in the format:/?q=fillpdf&fid=10&nid=10 - Using a single webform submission (common):
<a href="/fillpdf&fid=1&webform[nid]=3&webform[sid]=4">PDF</a> - Multiple nodes or webform submissions; later nids override conflicting fields (note: webforms without
sidK/code> default to latest submission) <code><a href="/fillpdf?fid=1&nids[]=1&nids[]=2&webforms[0][nid]=3&webforms[0][sid]=1&webforms[1][nid]=3">PDF</a>
To create the link in an existing field on a Views view:
- Add a Global: Custom text field
- For the main text, type in the text you'd like for the link. An example of this is Generate PDF
- Expand the option set labeled Rewrite results and click the checkbox for Output this field as a link. For Link path, use a link in the following format:
fillpdf?fid=1&webform[nid]=3&webform[sid]=4]You only need to set Link path, unless you know that you need other options on the link.
A more dynamic example of this is the following, which you could use in a list of Webform Submissions:
fillpdf?fid=1&webform[nid]=[nid_1]&webform[sid]=[sid_1]In this case, you need to add the Nid and Sid of the Webform twice and rearrange the first set (whose field tokens are
[nid]and[sid]) to be below the Global: Custom text field that you added. Otherwise, views will replace[nid]and[sid]with the actual Nid and Sid, and this can be confusing to troubleshoot.Finally, note that you can create a link field for nodes in a View as well. Refer to the standard HTML link formats above. From
fillpdfonward, the formats are the same, except for any dynamic replacements you choose to use in Views.
- Using a single node:
- Add the link in PHP (advanced). Examples:
- Using a single node:
<?php
echo l("PDF", fillpdf_pdf_link($form_id = 1, $node_id = 2));
?> - Using a single webform submission (common):
<?php
echo l("PDF", fillpdf_pdf_link($form_id = 1, null, $webform = array('nid'=>3,'sid'=>4)));
?> - Multiple nodes or webform submissions; later nids override conflicting fields (note: webforms without
siddefault to latest submission)<?php
echo l("PDF", fillpdf_pdf_link($form_id = 1, $nids = array(1,2), $webforms = array( array('nid'=>3,'sid'=>1), array('nid'=>3)));
?>
- Using a single node:
Query string parameter reference
These are the query string parameters that may be used in a Fill PDF URL:
- nid
- Integer. The CCK node from which to draw form data.
- nids
- Array of integer. The CCK nodes from which to draw form data. Ignored in nid is set.
- webform
- Integer. The Webform node from which to draw form data.
- webforms
- Array of integer. The Webform nodes from which to draw form data. Ignored in webform is set.
- fid
- Integer. The Fill PDF Form ID of the PDF to put the data into.
- sample
- If set to "true" (exact string), each field will be filled with its field name.
- download
- Integer. If set to 1, always send a PDF to the browser, even if a destination_path is set for the PDF.
- flatten
- Integer. If set to 0, leave form fields editable. Default is to flatten the PDF so that fields cannot be edited.
Handling the filled PDF
Fill PDF offers three ways to deal with the generated PDF:
- Prompting the user to download it
- Saving the PDF to a specific path
- Saving the PDF to a specific path, and then redirecting the user to that file. This generally allows them to view it in their browser.
Changing the redirect path
When a visitor clicks a Fill PDF Link for a PDF that is configured to be saved to a file, the visitor is redirected to the homepage by default. To change the place they are redirected, use the destination query string parameter that Drupal provides.
For example, this link — assuming the PDF is set up to be saved to file — will redirect the user to the homepage after saving: fillpdf?fid=1&nid=1
To make it redirect them to their user account page, use: fillpdf?fid=1&nid=1&destination=user
Notice the addition of &destination=1 to change the redirect path.
Updating the PDF
When you edit a Fill PDF configuration, look for the Update PDF upload field. You can upload a new PDF, and this will automatically transfer over mappings to the new PDF. Field mappings referencing a PDF key that can't be found in the new PDF will not be transferred.
Exporting and importing field mappings
If you upload a new copy of a PDF but don't want to update an existing configuration, you will need to copy the field mappings from the old version to the new one.
- Go to the /admin/structure/fillpdf page.
- Click "Export Fill PDF field mappings" next to the old PDF.
- Select-all and copy the "Fill PDF Form Mappings".
- Go back to the /admin/structure/fillpdf page.
- Click "Import Fill PDF field mappings" next to the new PDF.
- Paste in the box "Paste code".
- Click "Import".
Filling in PDF Image Fields
Drupal 6
- Ensure you have created a FileField or ImageField.
- When configuring your field mapping on the relevant PDF field screen, use the
[field_name-filefield-fid], where field_name is the name of your image field.
Drupal 7
- Ensure you have created a File or Image field for your content type.
- When configuring your field mapping on the relevant PDF field screen, use the
[stamp:field_name]pseudo-token, where field_name is the name of your image field.
Caveats
- You must use the PHP/JavaBridge fill method or a paid Fill PDF Service subscription.
- This currently only works when using node data to fill PDFs.
- The PDF field must be an Image Field created in Adobe LiveCycle Designer. Button fields are not known to work at this time.
Transforming field values
Sometimes the way Drupal stores field values isn't the way the PDF expects. For example, PDF checkboxes often need to be sent a value of Yes or Off to show checked or unchecked states, respectively. However, your field may be a Boolean or Integer field and store 0 or 1.
Using field value transformation, you can tell Fill PDF to send Off to the PDF instead of 0 and Yes instead of 1. This can be done at both the PDF and individual field levels, with field-level transformations overriding PDF-level ones. See the Transform Values section when setting up your field mappings for full instructions on how to configure this.
Comments
Under 'mapping your fields'
Under 'mapping your fields' in D7 the PDF upload is now found at /admin/structure/fillpdf