I am a creator — PDF Document Generator - Walter Brame

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2014 08:09 PM
------------------
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.
!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2015 11:02 AM
Hi Walter, thanks much for putting this up. Were you able to put up the documentation on this feature? I'm having quite a hard time to implement this feature, and some sort of documentation would help a lot.
Thanks and regards,
Felipe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2015 01:04 PM
Hi Walter, apologies for the double post, now with a few tries under my belt I have a better idea of what is going wrong with my implementation, I am not being able to input CSS styles. I need to have a custom PDF so for that I am using the macro approach you suggested a few posts ago, and now I have a macro with html inside the Jelly tags, but this html ha for example a table with border style, for example: <td style="border:1px solid black; padding: 5px;">259,200.00</td>
This works if I get a UI PAge to open up my macro, but if I use the above script, the PDF comes without that formatting.
I also re-worked the ui macro approach in order to put the CSS directly into the css variable in
var pdf = new GeneralPDF(new GeneralPDF.Document(null, null, null,
html), cStyleSheet, glideRecord);
But still the PDF comes with no formatting.
Could you please lend me a hand on this? Thank you!
Above the entire code that calls the Macro:
// 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 uiMacroName= 'pdf_generator_mock'; // <===== REPLACE_ME !!!
var cStyleSheet = '<style>table.reference {width:100%; max-width:100%; border-left:1px solid #000000; border-right:1px solid #000000; border-top:1px solid #000000; border-bottom:1px solid #000000; border-collapse: collapse; padding: 2px;} table.reference th { border-bottom:1px solid black; padding: 2px;}</style>';
/**
*
* This will create a PDF file using a UI Macro for the content
*
*
*/
var UIPage2PDF = Class.create();
UIPage2PDF.prototype = {
initialize : function(uiMacroName, cStyleSheet, 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), cStyleSheet, 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(uiMacroName, cStyleSheet, glideRecord);
// End script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2018 05:21 AM
Did you ever manage to solve this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2018 11:10 AM
Hi Chris,
I am running to same issues, did you get any lucky in cracking this formatting issues ?
Regards
Hemashekar Reddy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2018 01:24 AM
Hi,
Well some formatting can be done, like line-height, strong tags etc.
And we found that the latest patch for Jakarta 8b fixed the line issues for tables on PDF, so my tables now actually show the lines.
But, its very primitive... With a normal display the bottom line is over the text and the only way to fix that is to set the cellpadding option to 3, which increases the size of the cells too much for my taste... Its not possible to shift the text up with any CSS I've tried (and believe me I've tried...)
For a table with borders this works... :
<table style="width: 100%; font-family: Arial;" border="1" cellspacing="0" cellpadding="3">
I chose to create the entire document in table form, which gave me a bit more control on the line-height etc. :
<table style="width: 100%; font-size: 10pt; font-family: Arial;" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><span style="font-size: 16.0pt; font-weight: bold;">Header text</span></td>
</tr>
<tr style="line-height: 12pt;">
<td> </td>
</tr>
<tr style="line-height: 12pt;">
<td>1.1 Test list 1</td>
</tr>
<tr style="line-height: 12pt;">
<td>1.2 Test list 2</td>
</tr>
<tr style="line-height: 12pt;">
<td>1.3 Test list 3</td>
</tr>
<tr style="line-height: 12pt;">
<td>1.4 Test list 4</td>
</tr>
<tr style="line-height: 12pt;">
<td> </td>
</tr>
</tbody>
</table>
<p>${pdf_script:signature}</p>
I hope this helps you in some way 🙂