Generate PDF/Image node
The Generate PDF/Image node allows you to create PDF and image files (JPG, JPEG, PNG) from DOCX, HTML, or Base64-encoded files. You can use this node when you want to generate documents (PDF) or images (PNG, JPG, and JPEG) based on user inputs.
Use cases
- Flight boarding pass: Automatically generate a PDF of a boarding pass for users after booking a flight.
- Medical prescription: Generate a patient's prescription as a downloadable PDF or image that can be easily accessed after a consultation
Configure Generate PDF/Image node
Drag and drop the Generate PDF/Image node to the workflow in the flow editor.
You can select the following formats to convert:
To convert from docx to PDF format
To convert docx to PDF format, follow these steps:
Choose the Docs option.
Define the following fields:
- In Template: Click Upload file and upload the template based on which the PDF should be generated. This document should be in
.docx
format and have placeholder values wherever the dynamic data is to be inserted. The placeholder should be enclosed in single brackets, that is{placeholdername}
. For example, The user name is {user name}. - In + Add Variable Mapping: Enter the placeholder name that you have included in docx without the brackets in the left column and select a variable (in which the value is collected from the user) in the right column. You can mutiple placeholder names.
- Select an output format: Choose the PDF option as that's the only available option for docs.
- Store the response in an object variable. For example, 'pdf_response'.
- In Template: Click Upload file and upload the template based on which the PDF should be generated. This document should be in
Include a text node and enter this syntax:
{{{variables.pdf_response.file.url}}}
to view the pdf file.
Refer to the following gif to see how the docx format is converted to pdf.
To convert HTML to PDF/JPG/JPEG format
Choose the HTML option.
Define the following fields: i. In Select variable containing HTML string: Choose the variable that contains the HTML string. ii. In Select an output format, choose the format in which the file should be generated, PDF/JPG/JPEG/PNG. iii. Enable Advanced options to set the margin and dimensions based on which the file should be geenrated.
iv. Store the response in an object variable like 'pdf_response'. For example, pdf_response.
Include a text node and enter this syntax:
{{{variables.pdf_response.file.url}}}
to view the file in pdf or image format.
Refer to the following gif to see how the HTML format is converted to PDF/JPG/JPEG format.
To convert from Base64
There are two ways by which you can convert Base64 files from:
APIs
In Input type choose API.
In API, choose the API added to your bot. If your API has dynamic paramters, add nodes to collect that information from users.
In Path to a BASE64 key, enter the path to the BASE64 key.
Select an output format: Choose the PDF option.
To display PDFs from an API response, store the response in an object variable, for example pdf_response. Include a text node and enter this syntax {{{variables.pdf_response.file.url}}}
Variables
- In Input type choose Variable.
- In Select variable, choose the variable that contains the BASE64 file.
- Select an output format: Choose the PDF option.
Display the file through the File node. Simply choose the relevant variable from the fetch from variable dropdown, it will send the dynamically generated file as a PDF to the user.
Generate PDF file from CDN url
When PDF URLs are retrieved from an API response or internal database, you can use a custom script to generate a downloadable PDF file and share it with the user.
This is done by formatting the file details into a JavaScript object and storing it in a variable of type Object, which is then used in the File node to deliver the file to the user.
Let's say your API returns a PDF file URL like:
https://cdn.yellowmessenger.com/PpfArbF4dxlI1744625393376.pdf
You can format and return this URL in a structure supported by the File node using a script function.
Steps to implement
Step 1: Write a Function to format the File object. Use a function node or logic node to write the following script. It consists of PDF link and file name inside an object format expected by the File node:
return new Promise(resolve => {
// Replace the static link with your logic to extract the PDF link from API/database
// Example: let pdflink = data.variables.pdfLink;
let pdflink = "https://cdn.yellowmessenger.com/PpfArbF4dxlI1744625393376.pdf";
let obj = {
"file": {
"url": `${pdflink}`,
"name": "file name"
}
};
console.log(pdflink, "link of the file");
resolve(obj);
});
Note:
- url: Provide the full PDF URL.
- name: Provide the file name that will appear to the user when they download it.
Step 2: Store the response in an object variable
Save the output of the above function in a variable.
The variable should be of type Object.
Example variable name: pdfFileObject.
Step 3: Use the Object Variable in a File Node
Add a File node to your conversation flow.
In the Fetch from section, select Variable.
Choose the variable name used in Step 2 (example, pdfFileObject).