Configuration Options
PDF_EXTENDED_TEMPLATES
folder from your active theme to your uploads directory.It is simple to generate PDFs and have them attached to Gravity Form notifications. The following will send the default PDF template to all form notifications.
$gf_pdf_config[] = array(
'form_id' => 1,
'notifications' => true,
);
It's worth noting that each 'block' or 'node' as we like to call them is representative of one PDF. If you add a second node with the same form ID as the first you are creating two separate PDFs. If you would like to apply multiple options to a single node you can.
DEFAULT TEMPLATE-ONLY CONFIGURATIONexclude
to the field's Custom CSS Class option (in the fields Appearance or Advanced tab).- default-show-html - This option will display HTML blocks in your default template (added in v3.1.0).
- default-show-empty - All form fields will be displayed in the PDF, regardless of what the user input is (added in v3.1.0).
- default-show-page-names - If you are using page breaks you can display the page names in the PDF (added in v3.1.0).
- default-show-section-content - By default only the section break title is displayed in the PDF. Enabling this option will also show the section break content (added in v3.7).
/* set individual options for default templates */
$gf_pdf_config[] = array(
'form_id' => 1,
'template' => 'default-template.php',
'default-show-html' => true,
);
$gf_pdf_config[] = array(
'form_id' => 1,
'template' => 'default-template.php',
'default-show-empty' => true,
);
$gf_pdf_config[] = array(
'form_id' => 1,
'template' => 'default-template.php',
'default-show-page-names' => true,
);
$gf_pdf_config[] = array(
'form_id' => 1,
'template' => 'default-template.php',
'default-show-section-content' => true,
);
/*
* Or use a combination of the new options to achieve the results you want
*/
$gf_pdf_config[] = array(
'form_id' => 1,
'template' => 'default-template.php',
'default-show-html' => true,
'default-show-empty' => true,
'default-show-page-names' => true,
'default-show-section-content' => true,
);
By default the software doesn't attach PDFs to notifications. By using the notifications option you can choose to attach PDFs to all notifications of a form, or restrict it to particular notifications.
/* only send default template to the notification called Admin Attachment */
$gf_pdf_config[] = array(
'form_id' => 1,
'notifications' => 'Admin Notification',
);
/* multiple attachments but not all */
$gf_pdf_config[] = array(
'form_id' => '1',
'notifications' => array('Admin Notification', 'User Notification'),
);
/* attach PDF to all form notifications */
$gf_pdf_config[] = array(
'form_id' => '1',
'notifications' => true,
);
Using this option you can change the PDF name and even use MERGETAGS to customise the PDFs for each user.
$gf_pdf_config[] = array(
'form_id' => '1',
'notifications' => true,
'filename' => 'User {Name:1}.pdf',
);
$gf_pdf_config[] = array(
'form_id' => 1,
'template' => 'example-template.php',
);
You can change the default size of your PDF from A4 to a number of pre-defined sizes, including letter and legal, or use a custom size. You are also able to change if the document is landscape or portrait.
/* generate a PDF the size of US letter in landscape */
$gf_pdf_config[] = array(
'form_id' => 1,
'pdf_size' => 'letter',
'orientation' => 'landscape',
);
/* generate an A3 PDF document */
$gf_pdf_config[] = array(
'form_id' => 1,
'pdf_size' => 'A3',
);
/* generate a custom PDF (specified in millimeters) */
$gf_pdf_config[] = array(
'form_id' => 1,
'pdf_size' => array(150, 250),
);
mPDF supports a range of languages out of the box and if you are generating PDFs in RTL languages like Arabic or Hebrew you can call the RTL parameter to correctly display text in your PDF.
$gf_pdf_config[] = array(
'form_id' => 1,
'rtl' => true,
);
You can easily restrict what users can do with generated PDFs by applying privileges to the document. You can also password protect it and set a master password to prevent any of the security settings being modified.
To enable the security methods you first need to set the security option to true.
$gf_pdf_config[] = array(
'form_id' => 1,
'notifications' => true,
'security' => true,
'pdf_password' => 'myPDFpass', /* remember to CHANGE this */
'pdf_privileges' => array('copy', 'print', 'modify', 'annot-forms', 'fill-forms', 'extract', 'assemble', 'print-highres'),
'pdf_master_password' => 'admin password', /* remember to CHANGE this */
);
pdf_master_password
is omitted a random one will be generatedpdf_privileges
will deny all permissions to the user.The software will automatically make appropriate changes to your document to generates a valid PDF/A-1b document, however the following items cannot be automatically fixed and are disallowed:
- Watermarks - text or image - are not permitted (transparency is disallowed so will make text unreadable)
- PNG images with alpha channel transparency ('masks' not allowed)
$gf_pdf_config[] = array(
'form_id' => 1,
'pdfa1b' => true,
);
You can read more about generating a PDF/A1-b document on the mPDF website.
CREATE PDF/X-1a DOCUMENTS PDF/X-1a is a file format to facilitate printing of electronic documents. Two key elements to this function are the requirement for PDF/X-1a documents to be 100% self-contained, and all images need to be CMYK or spot colors.The software will automatically make appropriate changes to your document to generates a valid PDF/X-1a document, however the following items cannot be automatically fixed and are disallowed:
- Watermarks - text or image - are not permitted (transparency is disallowed so will make text unreadable)
- PNG images with alpha channel transparency ('masks' not allowed)
$gf_pdf_config[] = array(
'form_id' => 1,
'pdfx1a' => true,
);
You can read more about generating a PDF/X-1a document on the mPDF website.
SAVE PDF TO SERVER Use this option if you want to save the PDF to your server when an entry is submitted. This is useful if you aren't sending PDF notifications (which need to save the PDFs so they can be attached to emails) and would still like the PDFs generated.$gf_pdf_config[] = array(
'form_id' => 1,
'save' => true,
);
$gf_pdf_config[] = array(
'form_id' => 1,
'dpi' => 300,
);
You can generate and attach multiple PDFs on the same form by creating two different configuration arrays using the same form_id.
$gf_pdf_config[] = array(
'form_id' => 1,
'notifications' => true,
'template' => 'custom-template.php',
'filename' => 'Custom.pdf',
);
$gf_pdf_config[] = array(
'form_id' => 1,
'notifications' => true,
'template' => 'custom2.php',
'filename' => 'Custom Template 2.pdf',
);
GFPDF_SET_DEFAULT_TEMPLATE
is set to true
.global $gf_pdf_default_configuration;
$gf_pdf_default_configuration = array(
'template' => 'default-template.php',
'pdf_size' => 'A4',
);
We've put together an example that uses all the configuration options (minus the default template-specific options) for Gravity PDF.
$gf_pdf_config[] = array(
'form_id' => 1,
'notifications' => array('My Notification 1', 'My Notificaiton 2'),
'template' => 'custom-template.php',
'filename' => '{date_mdy}_Custom.pdf',
'rtl' => true,
'pdfsize' => 'A10',
'orientation' => 'landscape',
'security' => true,
'pdf_password' => 'mypass', /* remember to CHANGE this */
'pdf_privileges' => array('print', 'fill-forms', 'print-highres'),
'pdf_master_password' => 'admin password', /* remember to CHANGE this */
);
Settings
Property | Default | Type | Example | Description |
---|---|---|---|---|
form_id | N/A | Mixed - Integer/Array | 1 or array(1,2,5) | The ID of the form you want to apply the PDF configuration to. The only required option. |
default-show-html (v3.1.0+) | false | Boolean | true or false | This option will display HTML blocks in your default template. |
default-show-empty (v3.1.0+) | false | Boolean | true or false | All form fields will be displayed in the PDF, regardless of what the user input is. |
default-show-page-names (v3.1.0+) | false | Boolean | true or false | If you are using page breaks you can display the page names in the PDF. |
default-show-section-content (v3.7+) | false | Boolean | true or false | Enabling this option will also show the section break content. |
notifications | N/A | Mixed - String/Array/Boolean | "Admin Notification", array('Not 1', 'Not 2') or true. | The notifications you want to attach the PDF to. Leave blank will not attach PDF to notification. |
template | Default-template.php | String | "my-custom- template.php" | The template file used to generate the PDF document. Note: PDF templates are located in your active theme's PDF_EXTENDED_TEMPLATES folder. |
filename | form-{form_id}- entry-{entry_id}.pdf | String | "My Custom Name.pdf" or " User {Name:1}.pdf" | Change the name of the PDF file. You can now use a form's MERGE TAGS in the file name. |
pdf_size | A4 | Mixed - String/Array | "Letter", "A10" or array(50, 200) | Sets the PDF size. Can pass a string with pre-defined size or an array which sets the PDF width and height in millimetres. PDF Presets A0 - A10, B0 - B10, C0 - C10, 4A0, 2A0, RA0 - RA4, SRA0 - SRA4, Letter, Legal, Executive, Folio, Demy, Royal |
orientation | Portrait | String | "landscape" | Change the orientation of the PDF to landscape. Note: By default the orientation is portrait so you only need to add it for landscape PDFs |
rtl | False | Boolean | True | Change the text direction from right to left for languages like Hebrew and Arabic |
pdfa1b (v3.4.0+) | false | Boolean | true or false | Changes the PDF output to a PDF/A-1b document |
pdfx1a (v3.4.0+) | false | Boolean | true or false | Changes the PDF output to a PDF/X-1A document |
save (v3.4.0+) | false | Boolean | true or false | Save the PDF to your server on form submission. |
dpi (v3.4.0+) | 96 | Integer | 300 | Changes the image DPI. 96 is a good default, but it should be changed to 300 if the document is to be professional printed |
security | False | Boolean | True | Determines whether to restrict access to PDF. Use in conjunction with pdf_master_password, pdf_password and pdf_privileges. |
pdf_master_password | N/A | String | "aSAja4202$@@" | Restricts modification of the PDF document. If omitted a random password will be generated. |
pdf_password | N/A | String | "U5erPa55w%rd" | Restricts access to a PDF. If you pass an empty string there won't be a password on the PDF. |
pdf_privileges | N/A | Array | array('copy', 'print', 'modify', 'annot-forms', 'fill-forms', 'extract', 'assemble', 'print-highres') | Restricts what users are able to do with the PDF. Note: The use of print will only allow low-resolution printing from the document; you must specify print-highres to allow full resolution printing. Note: Passing a blank array or not passing anything to pdf_privileges will deny all permissions to the user |
Advanced Configuration
At the bottom of the configuration.php file is a number of constants that modify advanced program settings - most related to reducing the software's memory footprint. View the memory footprint portion of the documentation for more information about reducing memory usage.Property | Default | Type | Example | Description |
---|---|---|---|---|
GFPDF_SET_DEFAULT_TEMPLATE | True | Boolean | false | By default, forms that don't have PDFs assigned through the above configuration will automatically use the default template in the admin area. Set to false to disable. |
PDF_ENABLE_MPDF_LITE | False | Boolean | true | Reduce the memory footprint by disabling advanced features like advanced table borders, terms and conditions, columns, index, bookmarks and barcodes. |
PDF_ENABLE_MPDF_TINY | False | Boolean | true | Further reduce memory footprint by disabling all the features of Lite plus positioning, float, watermark and form support |
PDF_DISABLE_FONT_SUBSTITUTION | False | Boolean | true | Disable font substitution. The entire font file will be embedded in PDF. Note: embedding entire font files increases PDF file size. |
PDF_ENABLE_SIMPLE_TABLES | False | Boolean | true | Disable the advanced table feature and forces all cells to have the same border and background |