directus-extension-flow2pdf
v1.1.3
Published
This extension allows you to print pdfs from directus flows
Maintainers
Readme
Flow2Pdf
The flow2pdf extension is a bundle that allows directus to print data from flow results and liquid templates.
Requirements
- Node.js 18 or higher
directus-extension-flow2pdfinstalled on your Directus instance.
Usage
The extension will add a new interface, endpoint and operation to your directus instance. Find the configurations for each interface type below
Interface Configuration
- Create a Flow with
Webhooktrigger and set the method asPOST, now copy theidof the Flow. Make sure that the trigger is not asynchronous. - Create a
Button Linksfield in the desired collection and chooseFlow2PDFas the interface. - Create
extensions/templatedirectory and add your.liquidtemplate.

Flow Id: Id of the Flow you will be collecting data from (Note: the last operation of your Flow should return some JSON data ).Behavior: Accepts two valuesprint: To print the document from your printerdownload: To download the document as PDF
Template: the name of your liquid js template stored inextensions/templatesdirectory. The data from your flow will be passed to the liquid file.label: The label of the buttonIcon: The icon of the buttonType: The type of the button. Accepted values areprimary,secondary,warninganddangerPdf Options: Options to customize the generated pdf. You should provide a json with the following parameters:
|Name |Type |Default |Description |
|------------|----------------|--------------------------------|------------------------------------------------------------------------------------------------------------|
|margin |number or array |0 |PDF margin (in jsPDF units). Can be a single number, [vMargin, hMargin], or [top, left, bottom, right]. |
|pagebreak |object |{mode: ['css', 'legacy']} |Controls the pagebreak behaviour on the page. See Page-breaks below. |
|image |object |{type: 'jpeg', quality: 0.95} |The image type and quality used to generate the PDF. See Image type and quality below.|
|enableLinks |boolean |true |If enabled, PDF hyperlinks are automatically added ontop of all anchor tags. |
|html2canvas |object |{ } |Configuration options sent directly to html2canvas (see here for usage).|
|jsPDF |object |{ } |Configuration options sent directly to jsPDF (see here for usage).|
Template: the name of your liquid js template stored inextensions/templatesdirectory. The data from your last operation will be passed to the liquid file.
API endpoint
If you want to print a pdf from you own app (Vuejs, Reactjs, Angular...), you can use the exposed endpoint flow2pdf/print
Trigger the flow using the extension sdk Guide to trigger a flow
Run a POST request to the following endpoint
http://your-directus-instance.com/flow2pdf/printGuide run POST request on custom Directus endpointThe body should match format
{ "flow_data": { "property1": "value1", "property2": "value2" }, "template": "path to your template" }flow_datashould contained the response you received after the flow was triggeredtemplateis the path to your liquid file
If the request is successful you'll get a response with the following format
{"html": "The corresponding html"}You can then use
html2pdf.jsto transform the html output to a pdf
Extra
- You can add
MARKETPLACE_TRUST="all"option in your directus env variables to be able to browser API/Hybrid extensions within the marketplace section of your directus app.
