Skip to content

Instantly share code, notes, and snippets.

@nancystodd
Forked from mozrat/background.script.js
Created February 6, 2018 18:39
Show Gist options
  • Save nancystodd/bedc230611ec8f6d2209b3f3b7d1d1c7 to your computer and use it in GitHub Desktop.
Save nancystodd/bedc230611ec8f6d2209b3f3b7d1d1c7 to your computer and use it in GitHub Desktop.
ServiceNow PDF Generation
var UP3PDF = Class.create();
UP3PDF.prototype = Object.extendsObject(AbstractAjaxProcessor, {
_document : null,
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);
},
type: 'PDF'
});
var p = new UP3PDF();
p.createPDF('<p>Hello World!</p>', //HTML to convert to PDF
'incident', //Attach PDF to table
'85071a1347c12200e0ef563dbb9a71c1', //Attach PDF to record/sys_id
'myFile.pdf'); //attachment filename
@aki2116
Copy link

aki2116 commented Jun 7, 2021

Hi, I tried your code, though everything seems to be passing on the script include it's not generating the PDF
Getting the below error
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment