Generate Custom PDFs

Dinesh_gunda
Tera Contributor

Var PDF_Name = "Custom PDF";
var
pdfObj = new sn_pdfgeneratorutils.PDFGenerationAPI();
var result = pdfObj.convertToPDF('HTML_string', '<table_name>','<record_sys_id>',<PDF_Name>);
2 REPLIES 2

yella123
Tera Expert

@Dinesh_gunda 

var PDF_Name = "Custom_PDF_Name.pdf";  // Must end with .pdf
var pdfAPI = new sn_pdfgeneratorutils.PDFGenerationAPI();

// Your HTML string for the PDF content
var htmlContent = "<html><body><h1>Hello from PDF!</h1><p>This is a custom PDF document.</p></body></html>";

// Call convertToPDF()
var result = pdfAPI.convertToPDF(htmlContent, 'incident', 'incident sys_id', PDF_Name);

// Handle the result
if (result.getStatus() === 'success') {
    var sysId = result.getDocumentId();  // sys_id of the generated PDF (sys_attachment)
    gs.info("PDF generated successfully. Attachment sys_id: " + sysId);
} else {
    gs.error("PDF generation failed: " + result.getErrorMessage());
}

 

Please mark my answer as helpful/correct if it resolves your query.

Ankur Bawiskar
Tera Patron
Tera Patron

@Dinesh_gunda 

what's your business requirement and what's your question?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader