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

Generate PDF with Header Image

karthikdurga
Mega Expert

I have a requirement to generate pdf and attach it to a record. I've used OOB GeneralPDF script include and achieved that (code below). However, I am unable to pass header image and footer text. Any suggestions on how to pass header/footer ? Thanks in advance.

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'  

});

5 REPLIES 5

jodha231
Kilo Contributor

Hello Karthik, I am in similar situation and need to create pdf from html. however i am stuck at pdf generation. I tried your code but its not working.

I am holding all html content in a variable in business rule and want to print pdf and attach it to a record. Any help is appreciated.