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

why "GeneralPDF" not working, getting error like GeneralPDF not defined

Sironi
Kilo Sage

Hi All,

Kindly let me know why GeneralPDF not working

Error

gs.addErrorMessage("PDF generation failed: " + e.message);

GeneralPDF not defined.

Client SCript :

var responseBody = Contenthtml;
var letterheadHTML =
        "<html xmlns:o='urn:schemas-microsoft-com:office:office' " +
        "xmlns:w='urn:schemas-microsoft-com:office:word' " +
        "xmlns='http://www.w3.org/TR/REC-html40'>" +
        "<head><meta charset='utf-8'></head>" +
        "<body>" +
        "<div style='font-family: Calibri, sans-serif; padding: 40px; line-height: 1.6;'>" +

        "<div style='text-align: right; margin-bottom: 30px;'>" +
        "<img src='https://dev351275.service-now.com/customer_service_email_logo.png' style='width: 100%; max-height: 120px;' alt='Header Image'>" +
        "</div>" +

        "<div>" +
        "<p><strong>Date:</strong> " + new Date().toLocaleDateString() + "</p>" +
        responseBody +
        "</div>" +

        "<div style='text-align: center; margin-top: 50px;'>" +
        "<img src='https://dev351275.service-now.com/customer_service_email_logo.png' style='max-height: 80px; max-width: 300px;' alt='Footer Image'>" +
        "</div>" +

        "</div>" +
        "</body>" +
        "</html>";


var ga2 = new GlideAjax('global.AttachToRecord');
    ga2.addParam('sysparm_name', 'getPDF');
    ga2.addParam('sysparm_recordSysId', taskSysId);
    ga2.addParam('sysparm_tableName', tableName);
    ga2.addParam('sysparm_htmlContent', letterheadHTML);
    ga2.addParam('sysparm_ filename', 'Welcome.pdf');
    ga2.getXMLAnswer(function(response) {
        alert('PDF Attachment created successfully!');
    });

 

Script Include : GeneratingPDF(custom)

var GeneratingPDF = Class.create();
GeneratingPDF.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getPDF: function() {
       var table = this.getParameter('sysparm_tableName');
       var sysId = this.getParameter('sysparm_recordSysId');
       var htmlContent = this.getParameter('sysparm_htmlContent');
       var filename = this.getParameter('sysparm_ filename');

        this.createPDF(htmlContent, table, sysId, 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: 'GeneratingPDF'
});

 

 

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@Sironi 

please use latest PDFGeneration API

PDFGenerationAPI - Scoped, Global 

Generating Custom PDFs - using the new PDFGenerationAPI 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Thanks @Ankur Bawiskar .

Earlier it used to work nice way. but  not sure what happened in recent days "GeneralPDF" script include(OOB)  also not existed in system.

kindly clarify one thing please

var mymap = new Object();
mymap["HeaderImageAttachmentId"] = "563d5136870000106e337f9719cb0be3";
mymap["HeaderImageAlignment"] = "LEFT"; // valid values LEFT,RIGHT,CENTER
mymap["PageSize"] = "A4"; // valid values LEGAL,LETTER,A4
mymap["GeneratePageNumber"] = "false"; // valid values true/false
mymap["TopOrBottomMargin"] = "72"; // default value 72
mymap["LeftOrRightMargin"] = "36"; // default value 36


here

HeaderImageAttachmentId means Image sysId from db_image_list ?

Sironi_0-1757862618634.png

 

like header Image id , can we add Footer Image ID ?

 

@Sironi 

yes it's db_image.

I believe that GeneralPDF is deprecated and hence it's not working.

Please move to PDFGeneration API which I already shared above.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Sironi 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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