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.

Is it possible to Export PDF form with custom header/footer

Shailender2
Tera Contributor

Hi ,

We have platform offering "Export to PDF" in which I need to add custom header/footer.

I need to display company logo in the header and some confidential note in footer. Please let me know if any thoughts.

 

4 REPLIES 4

Aoife
Tera Guru

Yes, there is a PDF API:

https://docs.servicenow.com/bundle/sandiego-employee-service-management/page/product/human-resources...

Requires an HTML template, from an HTML Script type field, or hand hacked.  Can add header, footer and logo.

Aoife

Community Alums
Not applicable
var PDF = Class.create();

PDF.prototype = Object.extendsObject(AbstractAjaxProcessor, {

 

_document : null,

 

example : function (){

this.createPDF('<p>Hello World!</p>', //HTML to convert to PDF

'incident', //Attach PDF to table

'd324db7d2b9aa20072675aa419da1547', //Attach PDF to record/sys_id

'myFile.pdf'); //attachment filename

},

 

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'

});

Joro,

If you please, start posting code using the {;} code insert button on the editor, it makes it look much nicer and more readable.  Also, be sure to select the proper type once in the code editor.

Like this:

var PDF = Class.create();

PDF.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    _document: null,

    example: function() {
        this.createPDF('<p>Hello World!</p>', //HTML to convert to PDF
            'incident', //Attach PDF to table
            'd324db7d2b9aa20072675aa419da1547', //Attach PDF to record/sys_id
            'myFile.pdf'); //attachment filename
    },

    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'

});

Aoife

Community Alums
Not applicable

You have a point - noted and fixed!