Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Show stamp image in PDF by workflow using the PDF Generation API as per the image attachment in pdf

nikhil kamlekar
Tera Contributor

Hi Team,

 

I'm trying to generate the image in PDF using the PDF Generation API but it fails to add in PDF. I have stored the image in sys_attachment table and calling that using the sys_id. 
Other content is working fine but 'Image' is not generating. Adding Image is the new enhancement to existing workflow script.

Below workflow script:

//Initiate pdf

var pdf = new sn_pdfgeneratorutils.PDFGenerationAPI;

// var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");

// var pdf = new sn_pdfgeneratorutils.Document.createDocument(pageSize);

var sysId = current.sys_id;

var file_name;

 

//configure pdf

var pdf_config = new Object();

pdf_config["HeaderImageAttachmentId"] = "attachment_sys_id";

pdf_config["HeaderImageAlignment"] = "right";

pdf_config["PageSize"] = "A4";

pdf_config["GeneratePageNumber"] = "false";

pdf_config["TopOrBottomMargin"] = "72";

pdf_config["LeftOrRightMargin"] = "36";

pdf_config["PageOrientation"] = "POTRAIT";

var style;

var headerAndBody;

 if (current.cat_item == "item_sys_id") {

{

 file_name = "PDF Generated from RITM ";

 

     style = "<style>html{font-family:'Arial';}p{font-size: 12px;}.footer{font-size:10px;}</style>";

     headerAndBody = "<h6>" + current.variables.date.getDisplayValue() + "</h6><h6>TO WHOM IT MAY CONCERN<h6/><h6>" + "<h6/><h6> RE: LETTER </h6><p>This letter serves to confirm that, " + current.variables.employee_name.getDisplayValue() + " with employee number <br><br><br>Should you require any further information, please contact the " + " Human Resources Department " + "<br><br><br>Yours Sincerely,<br>" + "<br><br><br>"+" <br><br><br>(Signature)"+"<br> Human Resources"+"<br>Mobile: "+"<br>Email: "+"<br>";

}

var footer = "<div><p class='footer'>Directors: MJ (Chairman), FJ <sup>1</sup> (Chief Executive Officer), </span><span style='line-height: 120%;color: #7e8c8d;'>4630140434</span></span></p></div>"

// var image;

var image = new sn_pdfgeneratorutils.Image("f95c872897a93e50ac8138ffe153afcd");

image.setNoBorder();

pdf.addImage(image);

 

var html = style + headerAndBody + image+ footer;

var result = pdf.convertToPDFWithHeaderFooter(html, 'sc_req_item', sysId, file_name, pdf_config, "aebc2d49c3ad6a149db0003599011234");

We want to add image as per the below right side of Signature which is highlighted in yellow and image should locate as per yellow highlighted.

nikhilkamlekar_0-1765461624887.jpeg

 

 

 

 

0 REPLIES 0