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

Generate PDF from multiple records, with customized design

ceskie
Kilo Guru

Hello guys,

I have got to generate a PDF with contents from multiple records and customize its design/template to meet customers needs. I have spent several hours googling and I am out of ideas atm.

I am stuck at the PDF generation part.

I know there is OOB functionality Export directly from URL which can export any record or list by typing '?PDF' after the '.do', but there is no way (or tell me I am wrong) how to customize this generic 'form-like' looking template, also it can export only one record/list at a time.

Also, I have found generalPDF class (Script Include), which is global but restricted to global only (huh?) and then another class GeneralPdfUtils which is global and accessible from all scopes, but I have no idea how to use this one as there is no documentation nor comments and from the method names I have a general vibe its a no-use for my case.

My approach is sth like:

  1. code an UI page with appropiate html mark up and CSS media queries so its meets the branding and layout requirements
  2. fill in the UI page on the fly with data each time it is called (query the records smh via URL)
  3. make a "snapshot" of the UI page and export it to PDF
  4. fetch the PDF and append it to a record

Currently I am struggling to generate custom PDF in ServiceNow UI16.

I am restricted to scripting and/or OOB functionality, no 3rd party libraries, rest calls and definitely no paid plugins.

ANY ideas are welcomed and appreciated in advance!

5 REPLIES 5

Nitin Panchal
Tera Guru

Hi , 

Check this plugin - its free and you can define template which can be used to generate PDF 

https://developer.servicenow.com/app.do#!/share/contents/3429377_pdf_generator?v=1.02&t=PRODUCT_DETA...

 

Thanks,
Nitin

ceskie
Kilo Guru

A brief update. Two possible courses were considered - writing (editing) into .docx table via binary write method of GlideSysAttachment, or, creating a fillable PDF which will be filled in via GeneralPdfUtils Class. The first one was denied as too complicated and risky, so the second one will be implemented, even though its bit too far from ideal solution.

Tommy Jensen
Giga Guru

Please have a look at this post:
https://community.servicenow.com/community?id=community_article&sys_id=c89807bedb1fd74054250b55ca961...

 

The OOB pdf utility is horrible and does not support a lot of the modern html/css styling. 

I will probably be forced to drop the oob utility and use the library jspdf instead. This also has some limitations however it looks like it better support modern html/css.

jsDOC is client site thinge, in my case its terrible idea to delegate such a thing as creation of pretty huge PDF to the client. Also, I have heard people complain its pretty 'slow'. So be aware...