generate pdf in helsinki

ochiengboniface
Giga Contributor

Hallo SN,

I found this tutorial on how to generate pdf in geneva. (PDF Generation in Geneva ). I am trying to generate the same in Helsinki. I cant to seem to get it to work. Is there a method to get it to work in Helsinki?

1 ACCEPTED SOLUTION

Simplified code (Helsinki AJAX Script Include) for generating a PDF from HTML


example method you can call from a UI action (obviously you would want to replace the hardcoded bits with what you require)



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'


});


View solution in original post

23 REPLIES 23

Daniel Draes
ServiceNow Employee
ServiceNow Employee

Are the necessary plugins activated? There are at least two that could help:



PDF Generator (com.snc.pdf_generator)


WebKit HTML to PDF (com.snc.whtp)



I believe the first one is the one you need.


Hallo Dreas,



I have activated the Plugin. My problem was how to generate the pdf document. In the Script include (GeneralForm), it is commented that you can use :



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



to create the pdf.


I was trying to create a pdf from a glide record:



var gr=new GlideRecord("sys_user");


gr.addQuery("sys_id",'62826bf03710200044e0bfc8bcbe5df1');//


gr.query();


if(gr.next()){


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


}



but the pdf is not being attached to the record.


Am i missing something?


Regards,


Boniface


I guess yes


The 4th parameter you are using is intended to be some HTML which will be used to render the content of the document.



I believe the PDF generation has changed a bit between the releases. Have a look at script include GeneralForm as an example on how to create the PDF.


Hallo Draes,


sorry for the late feedback. We ended up going another route. But your input was helpful. Thanks