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
5 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)

3 Likes

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

11 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

3 Likes

@Ioana_Gligan do we still have this activity in UiPath PDF package ?
I cant see this in studio 2019.10.3 with UiPath.PDF.Activities 3.1.0.

Appreciate your inputs.

Hi @ramvashista85,
with version image
we still have the “Get PDF Page Count” activity image

My suggestion is to update to the latest version of the package :slight_smile:

Thank you @ydimitrova for quick response, PDF activities package version 3.4.0 doesnt appear in my UiPath Studio.

Does this require latest version of Studio?

Anyways I got the solution (PDF page count) using StreamReader.

Well, I am not sure but it might be. If you want you can give it a try.
My studio version is 2021.4.4

Yeah, it seems latest activity comes with newer studio versions.

Anyways below is the solution i implemented using StreamReader

  1. creates a variable streamReader of type StreamReader (system.IO.StreamReader) and assign the PDF file or path.
  2. Create 2 variables x and y of type MatchCollection (System.Text.RegularExpressions.MatchCollection) & RegEx (System.Text.RegularExpressions.Regex) respectively.
  3. Using assign activities, do the following-
    streamReader = new StreamReader(PDFFilePath)
    x = y.Matches(streamReader.ReadToEnd(),“/Type\s*/Page[^s]”)
    PageCount = x.ToString

Thank you!!

1 Like