Count Number of pages in Pdf using servicenow

Prajusha
Tera Contributor

I have an attach a pdf in my incident form . I want the total number of pages in the pdf without using any third party api. Tell me a background script for that or any other way . I want to show an alert box in my incident form which shows number of pages of the attachment attached to it

1 ACCEPTED SOLUTION

gauravmudgal
Kilo Expert

Please use the following Script:

 

var desc;

 var att = new GlideRecord('sys_attachment'); 

 att.get("373535a1878eee10778e43b90cbb3593"); //Replace this with sys_id of your attached document,

 att.query();

 if (att.next()) {

     var sa = new GlideSysAttachment();

     var binData = sa.getBytes(att);

     var v = new sn_pdfgeneratorutils.PDFGenerationAPI;

     var result = v.getPdfPageSizes(att.sys_id);

     var page_count = 0;

     for (k in result.pages_size) {

         if (result.pages_size.hasOwnProperty(k)) ++page_count;

     }

 

     gs.info(page_count);

 

 }

View solution in original post

4 REPLIES 4

Amit Verma
Kilo Patron
Kilo Patron

Hi @Prajusha 

 

The only option I could think of is Document Intelligence if you don't want to consume any third-party APIs. https://www.servicenow.com/docs/bundle/yokohama-intelligent-experiences/page/administer/document-int...

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

tell me how

 

gauravmudgal
Kilo Expert

Please use the following Script:

 

var desc;

 var att = new GlideRecord('sys_attachment'); 

 att.get("373535a1878eee10778e43b90cbb3593"); //Replace this with sys_id of your attached document,

 att.query();

 if (att.next()) {

     var sa = new GlideSysAttachment();

     var binData = sa.getBytes(att);

     var v = new sn_pdfgeneratorutils.PDFGenerationAPI;

     var result = v.getPdfPageSizes(att.sys_id);

     var page_count = 0;

     for (k in result.pages_size) {

         if (result.pages_size.hasOwnProperty(k)) ++page_count;

     }

 

     gs.info(page_count);

 

 }

Ankur Bawiskar
Tera Patron
Tera Patron

@Prajusha 

try the script shared by @gauravmudgal and see if that works

If not then you cannot use any OOTB method or class for this.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader