Generate and Send PDFs from Zoho Creator with Deluge

Generate, Email and Archive PDFs from Zoho Creator

Almost every Creator app eventually has to hand someone a document — an invoice, a work order, a signed agreement, a summary the client wants to keep. Creator will produce all of these as PDFs without any external service. There are three patterns worth knowing, and picking the wrong one is what makes this feel harder than it is.

Written from scratch. The original library entry for this topic was a title and nothing else — no script, no explanation. It was also flagged unpublished in the source platform, so it never reached anyone. This article is new.

Pattern 1 — email it, in one statement

If the PDF only needs to reach a person, do not generate a file at all. sendmail renders a report template straight into an attachment:

// Trigger: a button on a report, or On Success of a form
// Email a report template as a PDF attachment
sendmail
[
    from : zoho.adminuserid
    to   : input.Client_Email
    subject : "Your invoice " + input.Invoice_Number
    message : "<p>Hi " + input.Client_Name + ",</p><p>Your invoice is attached.</p>"
    Attachments : template:InvoicePrint as PDF
]

The template is an ordinary Creator report template, so you lay it out visually and Deluge never touches the formatting. This covers the majority of real cases.

Pattern 2 — get the PDF as a file you can pass around

When the document has to be stored, sent to another API, or base64-encoded for an e-signature service, fetch it as a file object:

// Fetch the PDF as a file object, then do anything you like with it
void PDF.archiveInvoice(int recordId)
{
    pdfFile = invokeurl
    [
        url  : "https://creatorapp.zohopublic.com/YOUR_ACCOUNT/YOUR_APP/report/Invoices/" + recordId + "/pdf"
        type : GET
        connection : "creator_oauth_connection"
    ];

    // a) Attach it back onto the record's file-upload field
    rec = Invoices[ID == recordId];
    rec.Invoice_PDF = pdfFile;

    // b) or push it to WorkDrive
    uploadResp = invokeurl
    [
        url    : "https://www.zohoapis.com/workdrive/api/v1/upload?filename=Invoice-"
                 + rec.Invoice_Number + ".pdf&parent_id=YOUR_WORKDRIVE_FOLDER_ID"
        type   : POST
        files  : pdfFile
        connection : "workdrive_connection"
    ];
    info uploadResp;

    // c) or base64 it for an API that wants an inline document
    docBase64 = zoho.encryption.base64Encode(pdfFile);
    info "base64 length: " + docBase64.length();
}

Pattern 3 — let the user print it

Sometimes the answer is not automation. A report’s built-in Print action already renders any template to PDF on demand, and a button that calls openUrl on the print URL gives the user a preview they can save themselves. Do not write Deluge for something the platform already does.

Notes

  • Design the template, not the HTML. Building PDF markup by hand in Deluge is a trap. Report templates handle pagination, headers and page breaks; a hand-built HTML string does not.
  • Do not put a private link in your script. Older tutorials fetch the PDF through a report’s private link, which is a permanent unauthenticated URL to your data. Use an OAuth connection instead, as above. If you have private links in existing scripts, regenerate them.
  • Fetching is not free. Rendering a PDF costs an API call and a few seconds. On a bulk job, generate in a scheduled function rather than inside a form workflow, or you will hit the script timeout.
  • Base64 for e-signature. Docusign wants documentBase64; Acrobat Sign wants a multipart upload to transientDocuments; Zoho Sign takes the file object directly. All three start from pattern 2.

This script is part of the free Creator Scripts Deluge Library.

All 39 Deluge scripts, the full Zoho Creator course, and every downloadable asset are now free. Get free access →