generate-pdf

The generate-pdf action allows you to quickly create a PDF file version of HTML content, whether a receipt, report, form, or other document.

The URI of the generated file is returned and is available as part of the action instance output. When you tap the button, the app compiles the necessary information and generates a file you can save, or share instantly.

Generate a PDF file
Generate a PDF file

Configuration options

Some properties are common to all components, see Common component properties for a list and their configuration options.

Core structure

html

Use standard HTML elements to ensure optimal formatting and compatibility when rendering content in the PDF file, for example, <html><body>Invoices are provided monthly.</body</html>. The HTML can be built up using JSONata or JavaScript.

fileName

Give the PDF a name, this name is used as the local file name, and is referenced as part of the uri, which can be accessed via the action's instance output ([email protected]). The .pdf extension is automatically added to the fileName.

title

Provide the action button with a title, for example, Invoice.

Other options

icon

Select a icon to display when the action is configured as the secondary button or in a jig-header.

isHidden

true hides the action button, false shows the action button. Default setting is false.

styles

  • isDanger - Styles the action button in red or your brand's designated danger color.

  • isDisabled - Displays the action button as greyed out.

  • isPrimary - Styles the action button in blue or your brand's designated primary color.

  • isSecondary - Sets the action as a secondary button, accessible via the ellipsis. The icon property can be used when the action button is displayed as a secondary button.

Considerations

  • You can reference the local PDF file using the action's output uri in other actions or components, [email protected]. For example, generate the PDF file then share the file.

  • Depending on where you save and use the saved PDF, you might need to use conversions.

  • The .pdf extension is automatically added to the fileName.

Examples and code snippets

Basic generate a PDF and share

Generate and share PDF
Generate and share PDF

In this example, an action list contains two actions: the first generates a PDF of a checklist, the second shares the PDF via a messaging app on the device.

Example: See the full code sample in GitHub.

Generate a pdf, save and share

In this example, an action list contains three actions: the first generates a PDF for an invoice, the second saves it to the database, and the third shares the PDF via a messaging app on the device. When saving the file to the database the file is converted from local-uri to data-uri for storage.

Example: See the full code sample in GitHub.

Generate PDF, save & share
Generate PDF, save & share

Generate pdf from JavaScript HTML function

This example demonstrates how to use a JavaScript function to generate an HTML invoice. The invoice is populated with customer details retrieved from a Dynamic Data datasource named invoices. The JavaScript function is referenced in an expression used by action.generate-pdf, after which the invoice is shared using the action.share via the device's apps.

Example: See the full code sample in GitHub.

PDF from JavaScript function
PDF from JavaScript function

Last updated

Was this helpful?