Background color is not being applied in HTML template for PDF generation

vidushi7
Giga Contributor

Background color is not being applied in HTML template for PDF generation

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Vidushi,

How are you generating the html template?

Is it some custom code or out of box?

Regards

Ankur

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

vidushi7
Giga Contributor

Ankur,

The code is custom.

We are generating PDF on UI action in which I am rendering HTML page and also replacing values from table's field after that I am using below script include to generate PDF:

Script Include:

var CustomPDFUtility = Class.create();
CustomPDFUtility.prototype = {
initialize: function() {
},


process : function(htmlPayLoad,tableName,sysID) {

gs.info("Invokedd >>>>>> ");
var payload = htmlPayLoad.toString();
this.createPDF(payload, //HTML to convert to PDF
tableName, //Attach PDF to table
sysID, //Attach PDF to record/sys_id
'Service_Forum.pdf'); //attachment filename
},

createPDF : function(html, table, sys_id, filename) {
var pdfDoc = new global.GeneralPDF.Document(null, null, null, null, null, null);
this._document = new global.GeneralPDF(pdfDoc);
this._document.startHTMLParser();
this._document.addHTML(html.toString());
this._document.stopHTMLParser();
this._saveAs(table, sys_id, filename);
},

_saveAs : function (table, sys_id, filename){
var att = new global.GeneralPDF.Attachment();
att.setTableName(table);
att.setTableId(sys_id);
att.setName(filename);
att.setType('application/pdf');
att.setBody(this._document.get());
global.GeneralPDF.attach(att);
},

 

 

 

type: 'CustomPDFUtility'
};

Hi Vidushi,

Since this is custom code you need to check which line of code is responsible for background color and accordingly debug

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Geoffrey2
ServiceNow Employee
ServiceNow Employee

I have not used GeneralPDF before. However, other PDF generators I have used only recognised older CSS methods. 

For example:

Instead of <td style="background-color:#ffffcc;">

Try <td bgcolor="#ffffcc">