The CreatorCon Call for Content is officially open! Get started here.

converting email to PDF

Swathi KS
Tera Contributor

I have written below script to convert email to PDF and attaching to the respective target it was working fine

But my email body content not fitting to the page in the PDF, please help me on this one.

 

 var html = "<p>" + current.subject + "</p>" + "<br>" + current.body; // you can fetch html body to pass on to the pdf

    var result = new sn_pdfgeneratorutils.PDFGenerationAPI().convertToPDF(html, current.target_table, current.instance, 'Original Compliance Notification');
    //body of pdf, table where you want to add the pdf, sys_id of the record where you want to add the generated pdf, name of file
    action.setRedirect(current);
2 ACCEPTED SOLUTIONS

Rafael Batistot
Kilo Patron

Hi @Swathi KS  

 

May this help you 

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1638958

If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.

View solution in original post

Bhuvan
Giga Patron
3 REPLIES 3

Rafael Batistot
Kilo Patron

Hi @Swathi KS  

 

May this help you 

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1638958

If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.

Ankur Bawiskar
Tera Patron
Tera Patron

@Swathi KS  

possibly because of styling.

try this

var html = '<html><head><style>' +
  '@page { margin: 1in; }' +
  'body { font-family: Arial, sans-serif; font-size: 12pt; margin: 0; padding: 0; }' +
  '.content { max-width: 7in; }' +
  '</style></head><body>' +
  '<div class="content">' +
  '<h2>' + current.subject + '</h2>' +
  '<div>' + current.body + '</div>' +
  '</div></body></html>';

var result = new sn_pdfgeneratorutils.PDFGenerationAPI().convertToPDF(html, current.target_table, current.instance, 'Original Compliance Notification');

action.setRedirect(current);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Bhuvan
Giga Patron

@Swathi KS  

 

See if below helps,

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0689606

 

https://www.servicenow.com/docs/bundle/yokohama-api-reference/page/app-store/dev_portal/API_referenc...

 

If this helped to answer your query, please mark it helpful & accept the solution. 

 

Thanks,

Bhuvan