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);
3 REPLIES 3

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
Tera Sage

@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