Skip to main content

PDF Download Link / URL

The [gravitypdf] shortcode and PDF merge tag display a link or URL to an entry's PDF in Gravity Forms confirmations and notifications. The shortcode can also be used on WordPress pages.

Before you get started...​

Gravity PDF restricts who can open a PDF. Review how PDF security works first, so your users don't get an access denied error. For the best balance between security and access, use signed PDF URLs.

What are Signed PDF URLs?

Auto-expiring URLs that let anyone with the link view the PDF. Use them to email a link to a third party, avoid storing IP addresses with entries, or link from a role-restricted page (if its author can view the entry). The shortcode and merge tag both support them, but you have to enable the feature.

Shortcode or Merge Tag?​

There are two ways to add an entry's PDF:

  1. Shortcode (recommended): displays a clickable link.
  2. Merge Tag: displays only the URL. Use it inside HTML attributes, where WordPress doesn't process shortcodes.
note

The PDF Link/URL can only be generated once the entry is saved in Gravity Forms. This is because you need a valid entry ID to build it.

Shortcode​

Use the [gravitypdf] shortcode to add a PDF link to Gravity Forms Confirmations and Notifications. To use it on any other WordPress page, add the entry attribute. If you only need the URL, add the raw attribute or use the PDF merge tag.

Using the Shortcode​

A "Download PDF" column on the PDF list

Copy the PDF's shortcode from the Download Shortcode column on the PDF form list, paste it into your confirmation or notification, and save. This displays a Download PDF link that downloads the PDF.

Confirmation Types​

Confirmations are shown to the user after they submit a form. There are three types:

  1. Text Confirmations
  2. Page Confirmations
  3. Redirect Confirmations

Whichever you use, submit a test entry and check the link opens the PDF.

Text Confirmation​

The [gravitypdf] shortcode in the Gravity Forms text confirmation

A text confirmation shows a message right after submission. Paste the shortcode from the PDF form list into the message and save.

Page Confirmation​

The [gravitypdf] shortcode in the Gravity Forms page confirmation

A page confirmation sends the user to an existing WordPress page.

  1. Paste the shortcode from the PDF form list into that page.
  2. In the confirmation, enable Pass Field Data Via Query String.
  3. Add entry={entry_id} to the field that appears and save.
info

For security reasons, signed PDF URLs are disabled for this confirmation type (as of v6.9.1). See when the shortcode signs the URL.

Redirect Confirmation​

The [gravitypdf] shortcode in the Gravity Forms redirect confirmation

A redirect confirmation sends the user to another URL, which can be the PDF itself. Paste the shortcode from the PDF form list into the confirmation and save.

tip

The Enhanced Download extension significantly improves the user experience of PDF redirect confirmations.

note

Pass Field Data Via Query String is ignored when redirecting to a signed PDF URL.

Usage in Notifications​

Adding the shortcode to notifications

Notifications are emails sent after a form is submitted. Instead of attaching the PDF, you can include a link to it with the shortcode.

Because of the default security protocols, an unsigned link suits recipients with a WordPress account. If users aren't logged in when submitting the form, or you're emailing a third party, use a signed PDF URL.

Building the Shortcode​

Use these attributes to change how the copied shortcode works.

Attributes​

ID (required)​
Name (optional)​
  • A label to show which PDF the shortcode is for. It doesn't change the link.
  • Example: [gravitypdf name="Proposal" id="560f2ef799945"]
Text (optional)​
  • The link's text. Defaults to Download PDF.
  • Example: [gravitypdf id="560f2ef799945" text="Save PDF"]
Type (optional)​
  • download (the default) saves the PDF or opens a save dialog, depending on the browser's settings. view opens the PDF in the browser.
  • Example: [gravitypdf id="560f2ef799945" type="view"] or [gravitypdf id="560f2ef799945" type="view" text="View PDF"]
Signed (optional)​
  • Creates a URL that expires and lets anyone with it view the PDF, whatever their user privileges.
  • It's an alternative to IP-based authentication, and works even if you've disabled IP addresses using the Gravity Forms Personal Data feature.
  • The URL isn't signed if the entry comes from a URL parameter (like a Page Confirmation) or a merge tag other than {entry_id}, or if the author of the post or page can't view the entry. See when the shortcode signs the URL.
  • Example: [gravitypdf id="560f2ef799945" signed="1"]
Expires (optional)​
Class (optional)​
  • Sets the class on the link (<a></a>), so you can style it. Defaults to gravitypdf-download-link.
  • Example: [gravitypdf id="560f2ef799945" class="my-custom-button-class"] or [gravitypdf id="560f2ef799945" class="my-custom-button-class a-second-class"]
  • Opens the print dialog when the PDF opens.
  • This depends on the PDF viewer. Adobe Reader and Acrobat support it unless the user turns it off, and Firefox supports it. Safari, Edge and Chrome don't.
  • Example: [gravitypdf id="560f2ef799945" print="1"]
Entry (semi-optional)​
  • Not needed in Gravity Forms confirmations or notifications, which already know the entry.
  • Needed everywhere else, unless the entry or lid URL parameter sets the entry (see Page Confirmation).
  • Use {entry_id} for the current entry.
  • With the signed attribute (see all the rules):
    • The URL isn't signed if a URL parameter or a merge tag other than {entry_id} sets the entry.
    • In post or page content, the URL is only signed if the post's author can view the entry.
    • Elsewhere outside Gravity Forms, like a widget, the URL is only signed if the current user can view the entry.
  • Example: [gravitypdf id="560f2ef799945" entry="250"] or [gravitypdf id="560f2ef799945"] with a URL like https://example.com/?entry=250
Raw (optional)​
  • Displays the URL instead of a link.
  • Example: [gravitypdf id="560f2ef799945" raw="1"]

When the Shortcode Signs the URL​

From Gravity PDF 6.18, a URL is only signed when the plugin can trust who chooses the entry. Otherwise you get an unsigned link, and logged out users may get an access denied error.

Shortcode location and entrySigned?
Confirmation or notification, with no entry, entry="{entry_id}", or an ID like entry="250"Yes
Confirmation or notification, with entry set by another merge tag, like entry="{Entry ID:6}"No
Post or page content, with an entry IDIf the post's author can view the entry
Elsewhere outside Gravity Forms, like a widget, with an entry IDIf the current user can view the entry, so never when logged out
Entry set by the entry or lid URL parameterNo
In a PDFOnly if the shortcode's entry is the one the PDF was generated from
Submitted in a form field, or added by a merge tagNo, the shortcode is displayed as text

A user can view an entry if they have a User Restriction capability, or they own it and Restrict Owner is disabled.

An entry set by a field's merge tag isn't signed because the person submitting the form controls the value and could open the PDF for any entry on its form. Developers who need this can create the URL with GPDFAPI::get_pdf_url().

Common Problems​

Enable Debug Mode and view the page as an Administrator. An error message explaining the problem appears where the shortcode would be.

Access Denied​

If a link using the signed attribute has no signature in its URL, it wasn't signed. See when the shortcode signs the URL.

Shortcode Displayed as Text​

A shortcode submitted in a form field or added by a merge tag doesn't run. Write it directly in the confirmation or notification.

Merge Tag​

Merge tags are placeholders Gravity Forms replaces with dynamic information in notifications, confirmations, PDFs and more. Learn more about merge tags.

Using the Merge Tag​

Gravity PDF Merge Tags are included in the merge tag selector automatically

On the form settings pages, select the merge tag selector ({..}). Your PDFs are listed under the Custom heading, prefixed with "PDF:".

The merge tag displays only the URL, like the raw shortcode attribute. You can use it inside HTML attributes, like <a href="{Label:pdf:6063bd0362dda}">...</a>, and anywhere Gravity Forms supports merge tags.

Building the Merge Tag​

The selector adds a basic merge tag. Use this structure to change it.

Usage / Structure​

{[label]:pdf:[id]} --> {Report:pdf:6063bd0362dda}

{:pdf:[id]} --> {:pdf:6063bd0362dda}

{[label]:pdf:[id]:[modifier]} --> {Report:pdf:6063bd0362dda:download}
  • [label] (optional): A name for readability. The selector uses the PDF Label.
  • :pdf: (required): Identifies the tag as a Gravity PDF merge tag.
  • [id] (required): The PDF's ID. The selector adds it for you, or you can find it in the pid parameter of the URL when updating the PDF settings.
  • [modifier] (optional): Changes the URL (see below).

Available Modifiers​

Add modifiers after the [id], separated by a :, in any order.

Download​
  • Downloads the PDF instead of opening it in the browser.
  • Example: {Report:pdf:6063bd0362dda:download}
Print​
  • Opens the print dialog when the PDF opens.
  • This depends on the PDF viewer. Adobe Reader and Acrobat support it unless the user turns it off, and Firefox supports it. Safari, Edge and Chrome don't.
  • Example: {Report:pdf:6063bd0362dda:print}
Signed​
  • Creates a URL that expires and lets anyone with it view the PDF, whatever their user privileges.
  • It's an alternative to IP-based authentication, and works even if you've disabled IP addresses using the Gravity Forms Personal Data feature.
  • To set how long it lasts, add a comma and a relative date format. This defaults to the Logged Out Timeout setting (20 minutes by default).
  • From Gravity PDF 6.18, it's capped at 1 year.
  • From Gravity PDF 6.18, a merge tag submitted in a form field or added by another merge tag isn't signed.
  • Example: {Report:pdf:6063bd0362dda:signed}
  • Example: {Report:pdf:6063bd0362dda:signed,5 minutes}
  • Example: {Report:pdf:6063bd0362dda:signed,1 month}
Multiple Modifiers​
  • Example: {Report:pdf:6063bd0362dda:signed:download}
  • Example: {Report:pdf:6063bd0362dda:print:signed,5 minutes}
  • Example: {Report:pdf:6063bd0362dda:download:print:signed,2 weeks}

Common Problems​

If no URL is displayed, the PDF may not exist on the current form, may be deactivated, or may have failed its conditional logic. To find out which, enable Gravity Forms logging, repeat the steps, and search the Gravity PDF log for PDF Mergetag is not valid.

PDF ID Invalid​

2021-04-01 04:29:59 (+00:00) - ERROR --> PDF Mergetag is not valid
|--> {"error":"You must pass in a valid PDF ID","tag":["{Zadani:pdf:6048493b8acce1}","6048493b8acce1",""]}

The PDF isn't on the current form. Check it exists on the form PDF list page, then use the merge tag selector to update the merge tag.

PDF Not Active​

2021-04-01 04:26:33 (+00:00) - ERROR --> PDF Mergetag is not valid
|--> {"error":"PDF is not currently active","tag":["{Zadani:pdf:6048493b8acce}","6048493b8acce",""]}

The PDF is turned off. Reactivate it on the form PDF list page.

Conditional logic did not pass​

2021-04-01 04:31:53 (+00:00) - ERROR --> PDF Mergetag is not valid
|--> {"error":"Conditional logic did not pass","tag":["{Zadani:pdf:6048493b8acce}","6048493b8acce",""]}

The entry didn't pass the PDF's conditional logic. This may be expected, but check the setting is correct.