johnelamont

Gold Country Business

Consultants

Be truthful. We are required to have true weights and measures because honesty lies at the heart of a strong and healthy community.
HTML to PDF (wonky)

by dev / February 19, 2024

There are circumstances when you’d like to email PDF attachments but your workflow requires a function. Zoho has no native HTML to PDF conversion facility, but this can be solved using a 3rd party HTML to PDF converter and the CRM functions, toFile and attachFile. Here is a code snippet that demonstrates this.
html = "<!DOCTYPE html><html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>";

key = "myAPIKey";

headers = map();

headers.put("Content-Type","application/json");

dataMap = map();

dataMap.put("key",key);

dataMap.put("html",html);

tCustomer = zoho.crm.getRecordById("TCustomers", ###############);

result = invokeurl

[

 url: "https://api.easypdfserver.com/make-pdf"

 type: POST

 parameters: dataMap.toString()

 headers: headers

];

resp = zoho.crm.attachFile("TCustomers", tCustomer.get("id"), result);

info resp;

sendmail

[

 from: zoho.loginuserid

 to: zoho.loginuserid

 subject: "test attachment"

 message: "we are testing attachments"

 Attachments :file:result

]
In the above example I am making use of EasyPDFServer to perform the HTML to PDF conversion. Once I get the file (result) it’s simply a matter of saving the attachment and then attaching it to an outgoing email. If you are concerned about storage, don’t save the attachment to a module.

Leave a Reply

Your email address will not be published. Required fields are marked *