I am a creator — PDF Document Generator - Walter Brame

walter_brame
ServiceNow Employee
ServiceNow Employee

------------------

EDIT

------------------

A lot has changed over the years.

Be sure to check here first:

https://developer.servicenow.com/dev.do#!/reference/api/quebec/server/sn_pdfgeneratorutils-namespace/CellBothAPI?navFilter=pdf

Have also enjoyed repurposing Webkit HTML to PDF plugin:

https://docs.servicenow.com/bundle/geneva-performance-analytics-and-reporting/page/use/performance_analytics/task/t_ActivateWHTP.html

------------------

ORIGINAL

------------------

PDF Document Generator is used by the ServiceNow, Inc. sales organization and is a generic HTML form creation and PDF Document generation framework.   The framework supports creating HTML forms and PDF files using any UI Form in the instance as a template.

 

The PDF Document Generator will replicate how that standard UI Form looks but then provides the functionality to change it easily as a front-end user without requiring development.

 

A PDF feature exists today in the standard platform but it is not customizable. The PDF Document Generator allows for rapid deployment of multiple templates and making changes on the fly to every component visible on the screen very quickly and easily.

 

Previously, the Sales organization was challenged with the ability to produce Quotes and Sales Orders from a CRM environment. With this custom ServiceNow, Inc. app in place, it is now possible for the front-end business users (sales operations, systems managers, administrators, power users, non-developers) to access configuration tools that put control of the following features directly into their hands:

 

- Add/remove fields as needed

- Change any fields placement and the field's label, orientation, or value

- Change any section/grouping or fields / Table of information (E.g. "Section 1", "Section 2", etc.)

- Add/remove new sections present in the form

- Manage an entire section's placement, splits, annotations, and headers

- Re arrange the placement of components in the form (E.g. one component relative to the next)

- Change the look and feel (color, border, padding, alignment, etc.) via common HTML and CSS style attributes.

- A scripting API to create dynamic conditions to change any aspect of the form and data (style, value, label, section, etc.).

- Save templates of form layouts

- Preview and print to PDF

 

The functionality of this PDF Document Generator was made possible by leveraging the ability to write custom scripts in the standard ServiceNow platform, and by having access to the backend table structure and data where forms are stored in the instance (standard UI page, CSS, HTML, and JavaScript).   A single developer, in a time frame of one business quarter, built the PDF Document Generator.

 

pdf_doc_gen_img_1.png

pdf_doc_gen_img_2.png

pdf_doc_gen_img_3.png

pdf_doc_gen_img_4.png

pdf_doc_gen_img_5.png

pdf_doc_gen_img_6.png !

 
99 REPLIES 99

HI Davin,



It is possible to generate the PDF file using a UI Macro for the content. A UI page can load the UI Macro for the UI Page content and the PDF Document Generator can create a PDF file using the same UI Macro.



Here is one way to do it:



// Begin script



// This holds your Jelly and HTML content


// and the Marco may be used by a UI Page to


// show the content in a UI Page


var uiMarcoName = 'pdf_demo_ui_marco'; // <===== REPLACE_ME !!!



/**


*


* This will create a PDF file using a UI Macro for the content


*


*


*/


var UIPage2PDF = Class.create();


UIPage2PDF.prototype = {



  initialize : function(uiMacroName, glideRecord) {



  // Get the rendered result of the HTML from the Jelly XML


  var html = new GeneralFormFormatter({


  name : uiMacroName,


  root : glideRecord,


  mode : 'pdf'


  }).get().getValue('value');



  // Create a PDF file by parsing the HTML


  var pdf = new GeneralPDF(new GeneralPDF.Document(null, null, null,


  html), null, glideRecord);


  // _parse method should be changed to public if used this way


  pdf._parse();



  // Create an attachment for the PDF and add to the GlideRecord


  GeneralPDF.attach(new GeneralPDF.Attachment(glideRecord.sys_id,


  glideRecord.getTableName(), 'My PDF File', pdf.get(),


  'application/pdf'));


  },



  type : 'UIPage2PDF'


};



/**


*


* Test it


*/


var glideRecord = new GlideRecord('u_pdf_document_generator_demo');


glideRecord.get('u_name', 'Testing 3');



new UIPage2PDF(uiMarcoName, glideRecord);



// End script



Regards,


Walter


It rocks!


domaners
Kilo Guru

I logged a ticket on Hi to see if I could get access to the API's for PDF output as I was trying to make something exactly like h=this. I was told no, but this is brilliant. Will be trying this out asap, and maybe reverse engineering the code to see what else can be done


Thank you very much Adam I will be very appreciative if you get a chance to dig into the code. There is a lot we can do with this and I am eager to see what people come up with !!


kelvin_du
Giga Contributor

Hi Walter,


I tried this but it did not work. When I click "Create PDF", it automatically redirected to previous page and did nothing.


Some info about instance:


  • Build name: HEAD (Dublin)
  • Build date: 11-05-2013_1800
  • Build tag: glide-dublin-09-13-2013__patch0-hotfix1-11-05-2013


Then I tried this on another instance, it worked.


Some info about 2nd instance:


  • Build name: Dublin
  • Build date: 02-11-2014_1308
  • Build tag: glide-dublin-09-13-2013__patch0-hotfix8-02-04-2014



I need this PDF Document Generator work on first instance.


Please give me some suggestions.


Thank you so much.