convert email to PDF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I have written below script to convert email to PDF and attaching to the respective target.
But my email body content not fitting to the page in the PDF, please help me on this one
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
15 hours ago
Hi @Swathi KS ,
To ensure your email body content fits properly on the PDF page when using ServiceNow's PDFGenerationAPI, you can try the following two solutions:
Solution 1:
The PDFGenerationAPI processes HTML and can interpret CSS for styling and layout. You can embed CSS directly into your html variable to control the appearance and flow of your content. So:
- Reduce the font size and line height of the body content to fit more text on a single page.
- Define page margins to provide more usable space for the content. You can use the @page CSS rule for this
You can follow the given article on how to use PDF Generation API:
https://medium.com/@elhaminamdar/how-to-use-servicenow-pdf-generation-api-36d6c4aed6a3
Example of embedding CSS:
var emailBody = current.body;
var html = "<style>" +
"@page { size: A4; margin: 0.5in; }" + // Set page size and margins
"body { font-family: Arial, sans-serif; font-size: 10pt; line-height: 1.2; }" + // Adjust font size and line height
"p { margin-bottom: 0.5em; }" + // Reduce paragraph spacing
"</style>" +
"<p><b>" + current.subject + "</b></p>" +
emailBody; // current.body is assumed to be HTML content already
var result = new sn_pdfgeneratorutils.PDFGenerationAPI().convertToPDF(html, current.target_table, current.instance, 'Original Compliance Notification');
action.setRedirect(current);
Solution 2:
Use convertToPDFWithHeaderFooter for more control (Advanced): If simple CSS adjustments aren't enough, the PDFGenerationAPI offers another method, convertToPDFWithHeaderFooter, which provides an Object documentConfiguration parameter. This allows you to explicitly define page properties like PageSize, TopOrBottomMargin, and LeftOrRightMargin outside of the HTML, giving you more granular control over the PDF layout
Here's a reference article:
https://www.servicenow.com/community/developer-articles/generating-custom-pdfs-using-the-new-pdfgene...
Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.