convertToPDF
Overview
This task provides a robust solution for converting HTML content or URLs into well-structured, high-quality PDF files.
By leveraging a powerful PDF generation service, it ensures accurate rendering of web-based content, including text, images, styles, and page formatting. The process is designed to maintain content integrity, supporting multi-page documents and page-break handling.
Syntax
zoho.file.convertToPDF(content/URL);
Parameter | Data Type | Description |
Content | STRING | A string containing valid HTML markup to convert. |
URL | STRING | A publicly accessible URL pointing to the file or webpage to be converted. |
Example
Convert HTML String to PDF in Zoho Deluge
This script demonstrates how to convert an HTML string into a PDF file using Zoho Deluge. It is particularly useful for generating dynamic documents such as reports, invoices, or certificates directly from HTML content.
// Define the HTML content with a page break between two sections content = "<html><body>HTML Content on page One <div style='page-break-after:always'></div> HTML Content on page Two </body></html>"; // Convert the HTML content to a PDF file file = zoho.file.convertToPDF(content); // Log the PDF file object details for verification info file; // Check and confirm if the returned object is a valid file info file.isFile();
Convert a URL to PDF and Rename the File in Zoho Deluge
This script demonstrates how to convert a publicly accessible URL to a PDF file and apply file-level operations, such as renaming the output using Deluge scripting.
// Step 1: Specify the URL to convert url = "https://www.zoho.com/deluge/"; // Step 2: Convert the URL content to a PDF file file = zoho.file.convertToPDF(url); // Step 3: Log file details and confirm file object info file; info file.isFile(); // Step 4: Rename the generated PDF file file.setFileName("CRMAccounts"); // Step 5: Log the updated file object with the new name info file;
Usecase
A sales manager wants to archive monthly CRM dashboard reports as PDF documents for compliance and internal review automatically. These dashboards are hosted on a secure internal web URL and display key sales metrics, including revenue trends, lead conversions, and sales rep performance.
Each month, the manager wants:
- The dashboard page to be converted into a PDF.
- The file to be renamed with a standard naming convention (e.g., CRM_Monthly_Report_April_2025.pdf).
- The PDF needs to be saved or emailed for record-keeping and performance analysis.
// Define the URL of the public CRM dashboard (make sure it’s accessible if hosted internally) dashboard_url = "https://crm.zoho.com/reports/monthly-dashboard?month=April&year=2025"; // Convert the live dashboard page to a PDF file pdf_file = zoho.file.convertToPDF(dashboard_url); // Verify the file object if (pdf_file.isFile()) { // Construct a meaningful filename based on the report context report_name = "CRM_Monthly_Report_April_2025"; // Rename the file for easy identification pdf_file.setFileName(report_name); // (Optional) Save the file to WorkDrive, attach to an email, or upload to a record // Example: Send email to manager with attached file sendmail [ from: zoho.adminuserid to: "sales.manager@company.com" subject: "Monthly CRM Report - April 2025" message: "Attached is your monthly CRM performance dashboard." attachments: pdf_file ]; info "PDF report generated and emailed successfully."; } else { info "PDF generation failed. Please check the URL or network accessibility."; }
Response Format
Note: On success, the response will return a PDF file.
Failure Response for Exceeding Maximum URL Length
{"Message":"Unable to process your request","details":{"param name":"url","Error":"More than maximum length","StatusCode":400}}
Points to Note
- The maximum number of characters allowed for HTML content is 12,000,000.
- The maximum length of a URL that can be converted is 25,000 characters.
- The maximum processing time for a conversion request is 301 seconds.
- The converted PDF files support built-in file operations, such as renaming using setFileName().