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

Certain HTML styles are not loading in GeneralPDF.Document

Joey Wan Kenobi
Tera Guru

Hello,

I created a script include that provides a create PDF functionality using the OOTB GeneralPDF script include. It successfully creates the document and attaches it to the ticket.

Some styles, however, are not being applied (for example, 'background-color' on <td> and border on <table>). Is it possible to get these styles to apply? If so, how? Has anyone had success doing so? I looked at the OOTB GeneralPDF script include, and it is almost as if it wasn't finished.

Here are the main functions in the script include that I created:

createPDF: function (html,table, sys_id, filename) {

  var pdfDoc = new GeneralPDF.Document(null, null, null, null, null, null);

  this._document = new GeneralPDF(pdfDoc);

  this._document.startHTMLParser();

  this._document.addHTML(html);

  this._document.stopHTMLParser();

  this._saveAs(table, sys_id, filename);

},

_saveAs: function (table, sys_id, filename){

  var att = new GeneralPDF.Attachment();

  att.setTableName(table);

  att.setTableId(sys_id);

  att.setName(filename);

  att.setType('application/pdf');

  att.setBody(this._document.get());

  GeneralPDF.attach(att);

},

9 REPLIES 9

Joey Wan Kenobi
Tera Guru

I submitted a question to HI. If they have anything, Ill post it here.



If anyone has found a way around to accomplish this, please let me know


Hey Captain,



Have you heard anything back?



I have the same question for ServiceNow/HI. After spending the last two days scouring through this application and all the script Includes (including walter's additional ones), the bulk of the problem is that, even in Geneva, ServiceNow is still using an old version of itext. HTMLWorker was deprecated 4 years ago, and unfortunately they don't have XMLWorker accessible (that I can tell).



A work-around for background color is to set the attribute bgcolor (html) instead of by css(background-color:yellow). I have not found a work-around for borders, though, and from what I can tell snooping around on the net, HTMLWorker may just not support any types of borders. XMLWorker does however.


Did you get a response?


shivanipatel
ServiceNow Employee
ServiceNow Employee

Joseph,



We are glad you took advantage of the ServiceNow Community to learn more and to get your questions answered. The Customer Experience Team is working hard to ensure that the Community experience is most optimal for our customers.



If you feel that your question was answered, we would greatly appreciate if you could mark the appropriate thread as "Correct Answer". This allows other customers to learn from your thread and improves the ServiceNow Community experience.



If you are viewing this from the Community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thanks,


Shivani Patel


Unknown-1.png


Rahman4
Tera Guru

Hi,

Did anyone managed to resolve this? I have similar issues. Styles are not working at all and page is always portrait.

TA