PDF Page Count Activity

Please add a new activity that accepts a path to a PDF file and returns the number of pages that the PDF has. There have been a few different packages that have had this, but they appear to not be maintained any longer. This is something that’s very basic for PDFs, so it’s something that should probably be included in the main packages without asking people to go outside of standard UiPath packages to get.

Continuing the discussion from Extracting pdf page count without using regex:


EDIT: While we wait for an official activity, here's a reusable component for anyone that just wants something to drag and drop. Give it a PDF file path, get back a number: [PDF_GetPageCount.xaml|attachment](upload://svdnVZHwzipZYnrhJdBlaeyWUmZ.xaml) (8.3 KB)

You can do it using PdfSharp library inside a invoke code activity (count is an Out argument):

Dim doc As PdfSharp.Pdf.PdfDocument = PdfSharp.Pdf.IO.PdfReader.Open("C:\Users\bruno\Desktop\doc.pdf", PdfSharp.Pdf.IO.PdfDocumentOpenMode.Import)
count = doc.PageCount
doc.Dispose
doc = Nothing
2 Likes

This requires that one installs the PDFsharp library however for a very simple task that a lot of people dealing with PDF’s may have. That method seems overkill and so an activity in the main UiPath package would be the better option. Thank you for the workaround however.

3 Likes

Ok i understand i will post this just as a reference, will work without installing any packages/libraries but the uipath official pdf activities:

Dim doc As BitMiracle.Docotic.Pdf.PdfDocument = New BitMiracle.Docotic.Pdf.PdfDocument
doc.Open("C:\Users\bruno\Desktop\doc.pdf")
count = doc.PageCount
doc.Dispose
doc = Nothing
4 Likes

Oh, nice! Thank you for that.

While we wait for an official activity, here’s a reusable component for anyone that just wants something to drag and drop. Give it a PDF file path, get back a number: PDF_GetPageCount.xaml (8.3 KB)

1 Like

Do I use your xaml file by the Invoke Workfile File activity? I am attempting to do that, passing the path to the PDF as an argument and also passing an “out” argument to receive the page count, and when I do I get an error: “Cannot create unknown type…” with a lengthy description. Do I need to do something else to configure this? Thanks!

Hello Peter, welcome to the forum.

You’re right, you use the Invoke Workflow activity, import the arguments, and then it should be ready to use.

See this example:
image

Here’s how my arguments look:

And here’s the output I got:
image

Ok, thank you for the prompt response!

Thanks again, it’s working correctly now!

1 Like

Hi,
Thank you for your suggestion. I added it to our internal ideas tracker for our team to consider.

Hi @dmccammond

It was released today in UiPath.PDF.Activities 3.2.0-preview, in the activity “Get PDF Page Count” :slight_smile:
Please give it a test :slight_smile:
image

3 Likes

I know it is asking too much, but could also be an output of the pdf reading activities :slight_smile:

Hello all,

This is completed. Starting with the latest official version, there is a “Get PDF Page Count” activity in the UiPath.PDF.Activities package :slight_smile:

Cheers,

Ioana

2 Likes