web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Count number of pages ...
Power Automate
Unanswered

Count number of pages of a PDF

(0) ShareShare
ReportReport
Posted on by

I built a flow to count the number of pages of a PDF using the expression below that I found in one of the forums:

 

sub(length(split(replace(base64ToString(outputs('Get_file_content')?['body']['$content']), 'Type/Pages', ''), 'Type/Page')),1)

 

It was working well until a while ago. Now the flow no longer counts the number of pages and neither is reading the PDF to include the DocuSign tabs. 

 

For context, I receive several documents from a supplier that I need to put the number of pages that each one has in an Excel and send for signature in the appropriate fields. Since January, the flow that I built in December and which was working very well, is no longer working and the only difference I noticed was that the PDF version that used to be 1.4 became 1.7.

 

Can anyone tell me why this is happening and how to resolve it?

 

I already tried to see some ways to convert these PDFs to 1.4 to see if it worked, but I couldn't find it.

Categories:
I have the same question (0)
  • Matthy79 Profile Picture
    4,180 Super User 2024 Season 1 on at

    Hello @ThauanyMoraes,

     

    In case you haven't found a workaround already. You could also use "Recognize text in an image or a PDF document" and check for the length of the result.

  • prathamesh26 Profile Picture
    18 on at

    Hi!

     

    I have figured out how to do this the smarter way. This solution works for all kinds of PDFs (scanned included) unlike other solutions listed here which work only for some but not all PDFs. 

     

    See flow below:

    prathamesh26_0-1699515901121.png

     

     

    Formula: length(body('Parse_JSON'))

     

    To get the schema for the Parse JSON action, build the flow up to the AI model action "Recognise text in an image or a PDF document". Run it and then go to the run history, copy the output of the "Results" property, come back to editing the flow and paste it in the "Generate from sample" section of the action.

     

    Voila! This works for all PDF types and returns the count of total pages in a PDF.

    Hope this helps! 

    prathamesh26_1-1699515900605.png

     

     

  • Matthy79 Profile Picture
    4,180 Super User 2024 Season 1 on at

    Isn't this exactly the same as I already suggested with an additional "Parse JSON" that is not needed?

  • prathamesh26 Profile Picture
    18 on at

    Well to be fair, I visited this thread last before your response and I hadn't seen your approach to it. Once I figured it out, I came back to respond with my solution. I never tested for whether it would work without having to pass the "result" attribute through a Parse JSON action, but my understanding at that time was that it would work with a Parse JSON action.

  • DTV Profile Picture
    21 on at

    I have a flow that's using "Extract Information from forms" action of Ai builder to get the content of PDF documents - can I get the total page count from that itself ? Alternately if I add the "Recognize text in an image or a PDF document" step as you mentioned here, then will that increase the AI builder units consumed by my flow ?

     

    I did read somewhere to use "Prediction output - page count" or something like that but I don't see such a dynamic content available from the "Extract Information ..." mentioned above.

  • Matthy79 Profile Picture
    4,180 Super User 2024 Season 1 on at

    Hello @DTV 

     

    I don't see an action "Extract Information from forms" at AI Builder. But just look at the output and search for information about what you are searching for.

  • MelodySJ Profile Picture
    2 on at

    Hi @ThauanyMoraes ,

     

    I needed the same function and saw the post with this expression. Which did not work for me from the start. I saw your post and tried to dig into the expression a little. 

     

    I found that for my pdf documents there is a space between "Type" and "/Page"

     

    I adjsuted the expression and it works for me now: 

     

    sub(length(split(replace(base64ToString(outputs('Get_file_content')?['body']['$content']), 'Type /Pages', ''), 'Type /Page')),1)
     
    Hope it will continue to work for awhile... / power automate comes up with an out of the box solution >.<

     

    Regards,

    Sijing

  • Suggested answer
    HS-24091713-0 Profile Picture
    2 on at
    Below expression is not working for all PDF's, even for those pdf which have blank pages and not having Page No.s.
     
    sub(length(split(replace(base64ToString(outputs('Get_file_content')?['body']['$content']), 'Type/Pages', ''), 'Type/Page')),1)
  • Suggested answer
    CU28110220-0 Profile Picture
    on at
    I was looking for a way to count pages in a PDF, and this tool is amazing! No downloads or complicated steps—just instant results. https://pdfwordcounter.io/pdf-page-counter/
  • DR-09071820-0 Profile Picture
    3 on at
    @prathamesh26 

    In your response, you posted an image, can you repost this along with the expression? we are running into an issue where even though the document has multiple pages, we arent getting a page count. We believe as you suggested, that there are different "types" of pdfs and your solution works on all. 
     
    We would very much appreciate this! 
     
    Thanks in advance.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard