Skip to content

Instantly share code, notes, and snippets.

@mozrat
Created December 19, 2017 16:29
Show Gist options
  • Save mozrat/1d40f8594cd442e4c5bd18ad71b291cf to your computer and use it in GitHub Desktop.
Save mozrat/1d40f8594cd442e4c5bd18ad71b291cf 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment