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

Using borders inside the inline style attribute won't work, use the "border" attribute instead (<table border="x"></table>)


Hi Wallace,



Thanks for this it's really helpful, looking at the original source of 'GeneralPDF.Document' script include, I can find that if the first parameter is set to true you can generate the document as a portrait one but this does not work, do you have any ideas about this?


Hi



Does it work for scoped application also?



Regards


Deepak


For those interested, you might also want to have a look at https://www.dylanlindgren.com/2017/09/30/filling-pdf-forms-in-servicenow to generate fillable forms


Gosia Urbanska
Giga Guru

Hi,


I used script provided by Wallace Roets and I was able to create pdf from my "html";


However, I'm getting plain text in my pdf file, the document formatting is missing. (I'm using inline style only)


I would appreciate any ideas and suggestions


Thanks