1. Tasks
  2. Generate PDF

Tasks

Generate PDF

This task is used to generate a PDF of a predefined PDF template. The template can be created and edited within the Stubber UI. Custom data can be passed to a PDF template, such that dynamic data can be displayed in each PDF.

The rest of this document assumes familiarity with adding a task to a stub.

Basic usage

{
tasktype
:
generate_pdf
taskapigatewayuuid
:
3de7fb63-7514-4c64-b852-0fae474211a0
params
:
{
pdftemplateuuid
:
60ffc330-9cb0-4b27-a1e7-9e958c5eb3dc
data
:
{
stub
:
~~stub
new_file
:
{
filename
:
PDF {{stub.stubref}}.pdf

Parameters

pdftemplateuuid
required
string

This is the unique identifier for the pdf template to use in the task. It is automatically inserted when a pdf template is selected from the dropdown in the user interface.

Default: null


data
optional
object

The data to be passed to the pdf generation step. All data values in the pdf template will be substituted with these data values. See Examples section.

Default: null


new_file
optional
object

Parameters about the new pdf file that will be generated by the task.


new_file.filename
optional
string

The name that the newly generated pdf file should have. Example PDF {{stub.stubref}}.pdf

Default: null


Result

{
success
:
true
payload
:
{
file
:
{
filename
:
PDF 2024-01-01-XXXX-FAKE.pdf
originalname
:
PDF 2024-01-01-XXXX-FAKE.pdf
fileuuid
:
8142ce6c-f3cd-526c-a5d3-747799ed2b1a
contentType
:
application/pdf

Properties

file

The pdf file that was generated by the task.


file.filename

The name of the file that the task generated.


file.originalname

A duplicated of the file name.


file.fileuuid

The unique identifier for the newly generated pdf file on the Stubber system.


file.contentType

The content type of the newly generated pdf file, this will always be application/pdf


Using the User Interface

The user interface is where you will be able to delete, create or copy a PDF Template. It is also where you will select the PDF Template to modify it.

From the Tasks tab when editing an action, click the Edit Task icon to open up the task editor.

The above elements explained:

  1. Field to enter the template name when creating a new template from scratch
  2. Clicking this creates a new PDF Template with the name entered in (1) above. Once you have created a new template, you will need to refresh the page for it to appear in the Select PDF Template field (3)
  3. A select box to select a template you wish to duplicate, delete or edit.
  4. The template duplicate button. This will make a copy of the Template selected in (3) above, using the name entered in (1) above. Refresh the page for the new template to appear in the Select PDF Template field (3)
  5. The template delete button. This will delete the Template selected in (3) above. Be aware, no warning will be given, the template is removed upon clicking this button
  6. The edit template button. This will open the template for you to edit it within the Stubber page.
  7. Field to assign a filename to the pdf file that will be generated. You can use Inline Text Substitution when defining the filename. Don't forget to give the .pdf file extension.

The PDF Editor

When you edit a PDF Template, you will be presented with the screen as shown below. This is where you can use all the elements provided to build the contents and layout of your PDF.

WARNING

Remember to save your template regularly and before closing this editor window.

Examples

Here are some more examples, with screenshots of the resultant pdf files.

The basic usage with the result

This is the basic usage example, with a screenshot of the generated pdf at the bottom.

{
tasktype
:
generate_pdf
taskapigatewayuuid
:
3de7fb63-7514-4c64-b852-0fae474211a0
params
:
{
pdftemplateuuid
:
60ffc330-9cb0-4b27-a1e7-9e958c5eb3dc
data
:
{
stub
:
~~stub
new_file
:
{
filename
:
PDF {{stub.stubref}}.pdf
Result
{
success
:
true
payload
:
{
file
:
{
filename
:
PDF 2024-01-01-XXXX-FAKE.pdf
originalname
:
PDF 2024-01-01-XXXX-FAKE.pdf
fileuuid
:
8142ae6e-f3cd-526c-a5d3-747799ed2b1a
contentType
:
application/pdf


Generate a quote

Generate a quote, dynamically add in customer details and the line items of the quote via the data parameter, use jsonata to calculate totals.

The task definition:

{
tasktype
:
generate_pdf
taskapigatewayuuid
:
3de7fb63-7514-4c64-b852-0fae474211a0
params
:
{
pdftemplateuuid
:
redacted
data
:
{
stubref
:
~~stub.stubref
customer_number
:
~~stub.data.customer_number
customer_name
:
~~stubpost.data.customer_name
quote_details
:
{
quote_line_items
:
~~stubpost.data.quote_line_items
fee_line_items
:
~~stubpost.data.fee_line_items
quote_summary_notes
:
~~stubpost.data.quote_summary_notes
quote_totals
:
~~#jsonata#$sum(stubpost.data.quote_line_items.item_price_ex_vat)
quote_fee_totals
:
~~#jsonata#$sum(stubpost.data.fee_line_items.fee_price_ex_vat)
quote_grand_total
:
~~#jsonata#$sum(stubpost.data.quote_line_items.item_price_ex_vat) + $sum(stubpost.data.fee_line_items.fee_price_ex_vat)
new_file
:
{
filename
:
PDF {{stub.stubref}}.pdf

The data:

{
customer_name
:
Bob
quote_line_items
:
[
1 item  
0
:
{
item_code
:
16
item_description
:
J5N 35.340 FD
item_price_ex_vat
:
1269000
fee_line_items
:
[
1 item  
0
:
{
fee_description
:
PDI & Delivery Fee
fee_price_ex_vat
:
8500
quote_summary_notes
:
Quote for J5N 35.340 FD model truck
Result
{
success
:
true
payload
:
{
file
:
{
filename
:
PDF 2024-01-01-XXXX-FAKE.pdf
originalname
:
PDF 2024-01-01-XXXX-FAKE.pdf
fileuuid
:
d98ffae6-1657-5f0f-9a15-31f77aef1340
contentType
:
application/pdf

The generated pdf file: