Purpose

The get_pdf action allows the retrieval of a PDF file generated from a predefined PDF Template. It is a registered action within the PDF module of Wonderful Relations, enabling dynamic PDF creation based on provided parameters.

Example Usage in a Datatable Button

Call with a filename and an identifier. This will generate a PDF named certificate.pdf using the content from the PDF Template identified as yourproject_certificate. Additionally, the ID of the corresponding DataTable row is passed to the PDF Template.

Options

identifier

The identifier field specifies which PDF Template should be used for generating the PDF. This ensures that the correct template is applied when processing the request.

Key: identifier Value: (string) – The unique identifier of the PDF template

filename

The filename field allows you to define the name of the generated PDF file. If no filename is provided, the identifier is used as the default filename.

Key: filename Value: (string) – The desired name of the output file.

application_type

The application_type option defines how the generated PDF should be handled by the browser.

Key: application_type Value: “application/pdf;base64”

Example Use Case: If you want to view the PDF directly in the browser instead of downloading it, set: application/pdf;base64

target

The target option determines whether the PDF should open in a new tab or in the current window.

Key: target Value: _blank

use_parent

The option use_parent: true allows you to reference the parent element instead of a specific row ID.

Key: use_parent Value: true

Example Use Case: If you have a linked DataTable within a form, and a button in the header or footer of that DataTable triggers a PDF download, the button itself does not have a specific row ID. However, you may still need to generate the PDF using the data referenced by the parent form.

By setting use_parent: true, the PDF template retrieves data from the form’s context rather than requiring a row selection. This makes it ideal for DataTable header or footer buttons that apply to the entire dataset rather than a single entry.

Output

The GetPDF function returns a structured JSON response of Wonderful Relation Callback Type CALLBACK_TYPE_FILE, which follows the standard response format used for file-related actions in Wonderful Relations.

The returned JSON includes: • filename – The generated PDF’s filename. • data – The PDF file as a base64-encoded string. • application_type – Defines how the PDF should be handled (e.g., “application/pdf;base64” for inline viewing). • target – Specifies where the file should open (e.g., “_blank” for a new tab).

{
    "filename": "invoice_123.pdf",
    "data": "<base64-encoded PDF>",
    "application_type": "application/pdf;base64",
    "target": "_blank"
}