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 Walter,



It works perfectly now, thanks a lot for fixing this so quick!



Christophe


walter_brame
ServiceNow Employee
ServiceNow Employee

Version 1.3



1.3 Main File:


(Dublin, Eureka) "sys_remote_update_set_698559432b9521006c59ae6219da1563.xml"



(Calgary) "sys_remote_update_set_44c7d14bb49d6900178ecdf09e3c3c47.xml"


Calgary Download: https://share.servicenow.com/sys_attachment.do?sys_id=9ac819cb2b5d61004a1e976be8da15df



1.3 Patch File:


(Calgary, Dublin, Eureka) If you just want to patch 1.2 with the fixes use file: "sys_remote_update_set_09e791832b9521006c59ae6219da1572.xml"


Calgary Download: https://share.servicenow.com/sys_attachment.do?sys_id=6ec859cb2b5d61004a1e976be8da1536



Version 1.2 Fixes:



- There is a new StyleSheet being loaded into UI Pages as part of the Eureka platform update. This StyleSheet needs to be disabled when the page loads because it causes conflicts since there is nothing related to the platform UI loading in this page. This change is for Eureka but is backwards compatible with Calgary, and Dublin.


ty_roach
Tera Guru

Will this convert a custom UI Page to a PDF?


Hi Ty,



The application will automatically generate all of the content of a UI Page for you and that content would match the information in the ServiceNow standard Form. Then it can create the PDF file based on that content in the UI Page.



The application is a framework meaning it is a library of very generic scripts that can be changed easily be used for many different purposes.



Within the library of code that comes with the application, yes it is possible to create a PDF file from a custom UI page but that is not an implementation I provided a demo for out of the box.



The UI page just needs to load a UI Macro for the content and the application can create a PDF file from the UI Macro.



With that said here is one way I would 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


Walter,


would you be able to flesh out the code for generating PDFs from UI Pages \ Macros?   Unfortunately my skills \ knowledge aren't quite up to the task.


Cheers,


Davin