Creating a custom template allows you to control exactly how you want the generated PDF document to look. Our software uses HTML and CSS to generate the PDF documents, so you can use a language you already know to automate the document creation process with Gravity Forms. You also have full access to all PHP and WordPress functions and APIs to create advanced PDFs, and pull data from multiple sources.
Getting Started(S)FTP into your web server and navigate to the PDF_EXTENDED_TEMPLATES folder, which is in your uploads directory. Inside you'll find a directory labelled with your site name. If running a multisite you'll see multiple directories. Select the appropriate folder.
PDF_EXTENDED_TEMPLATESfolder from your active theme to your uploads directory.
Inside this directory structure you will find the PDF templates that we feed to the plugin. There are a number of example templates to show off the features of the plugin and help give you a starting point for building your PDF templates.
The first step you want to take is copy and rename one of the example template files. Do NOT copy any of the default template files, as they are missing vital snippets for creating custom template files.
Open your newly copied template file in your favourite editor and review the code. It's a standard looking HTML document with bits of PHP thrown in the mix.The PDF template structure
Like HTML, the
<body> section holds our structure. You should ensure any modifications to the
<body> are made in between the
The last step in preparing your new PDF template is to remove the old template's
Including Gravity Form Fields in Your TemplateThere are two methods you can use to access Gravity Forms data in your custom PDF template:
Configure the Plugin
configuration.php file and create a configuration node using the
template config option.
/* the very basic configuration telling the plugin to use your custom PDF template on form #3 */
$gf_pdf_config = array(
'form_id' => 3,
'template' => 'my-custom-template.php' /* you need to set this to your custom template name */
Once saved and uploaded back to your server you will be able to navigate to your form's entry page and view your custom PDF via the View PDF link.The View PDF button on the form's entry list page.
You can also view the PDF when viewing details of the entry. The PDF View and Download buttons are located in the right hand sidebar.The entry details page also has PDF View and Download buttons for easy access.
Using Custom FontsYou can include TTF font files in your PDF documents - provided the font author hasn't put restrictions on the font file. Users who need CJK-supported fonts in there PDFs will need to download and install extra fonts.
Supported HTML and CSSmPDF, the software we use to generate the PDFs, is extremely powerful but does have limitations in its HTML and CSS support. Most notably is the lack of cascading styles, elements fixed to either inline or block, and the limited float and fixed positioning support.
Before beginning on your custom PDF template we recommend you review the supported HTML and CSS tags and attributes.
Debugging TemplatesIn certain circumstances it is helpful to be able to view the HTML source that is being generated by your PDF template. To do this is as simple as adding
&html=1to your PDF URL.
First, view your PDF from the entries list page. Then modify the URL with the
&html=1 code. For example, the full PDF URL might look like this:
You can then view the HTML source or use a developers tool like Firebug to help you review the PDF template.