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 / Number of pages in a P...
Power Automate
Unanswered

Number of pages in a PDF file

(3) ShareShare
ReportReport
Posted on by 87

In a Flow I am building I would like to obtain the number of pages in a PDF document. Is there anyway?

Categories:
I have the same question (0)
  • abm abm Profile Picture
    32,865 Most Valuable Professional on at

    Hi @nana001 

     

    Unfortunately using Power Automate this won't be possible to do.

     

    Thanks

  • nana001 Profile Picture
    87 on at

    Abm, thanks for your message. 

     

    The only other potential solution that I could find is reading the PDF file in plain text as suggested here: Solved: Re: Extracting PDF meta data and document info - Power Platform Community (microsoft.com)

     

    However, I cannot seem to decipher the "/Pages" metadata for a PDF file. I looked through the ISO reference. Any idea how to potentially read a PDF file in plain text to get the total number of pages in it?

  • seewo Profile Picture
    59 on at

    Dear @abm @nana001 

             I found an imperfect solution for counting pdf pages in Power Automate: Here is the procedure for your reference:

    1: extract your pdf file and set "the index numbers of the pages " to large quantity which is clearly pages out of bounds to make error-"Page out of bounds"  happen .  😀

    2: Make sure continue flow run in Advanced: Page out of bounds and set " Go to next action" only.

    3: Get the last error and capture the error message, then split text by "," and get the textlist[1],  Convert to number, then -2 and get the right page number now.😀

     

    PIC_2021-05-26_15-45-13.pngPIC_2021-05-26_15-54-16.png

  • Verified answer
    Paulie78 Profile Picture
    8,422 Moderator on at

    @nana001  You can do this in a cloud flow quite easily:

    CountPDFPages.png

    Simply get the file content of a PDF file. And then create a compose action with the following expression:

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

    This will return you the count of pages within the PDF file.

  • Community Power Platform Member Profile Picture
    on at

    It works. Thank you.

  • Sandra Soniec Profile Picture
    128 on at

    @seewo Couldn't get the proposed solution using regex running. Thanks for the imperfect alternative, which works perfectly for my need.

  • Frederico Profile Picture
    46 on at

    I like the approach of @Paulie78 , and I'm trying to use it to solve my problem as well. I need to insert a page number at the bottom of my pdfs pages. 

     

    Is there a way (without using the enconde connector) to insert the pages number (and be incremental as word does) in a pdf or a HTML file using Power Automate?

     

    The following is my current flow (canvas app send to the flow a HTML code --> flow creates a file with the HTML ---> convert this file to pdf

    Frederico_0-1632412811501.png

     

    Thanks

  • JimJ Profile Picture
    8 on at

    Thank you, this was a lifesaver!
    For those unfamiliar, in Step 5  - Set Variable, you can expand the variable name to get 'Message.Trimmed.Trimmed' as shown below
    For Step 7 - Set Variable I manually modified the variable to add "[1]" to get textlist[1]

    JimJ_0-1639174171130.png

     

  • SCGC_Developer Profile Picture
    2 on at

    This one is not work for some types of pdf . For ex, Pdf which was built from scan to pdf ( scan from machine)  anyone has ideas ?  

  • minhvo Profile Picture
    24 on at

    I found a solution when using AI model for extracting information.

    From AI model, 'predictionOutput' variable contains the "pageCount".

    For example, my pdf file has 2 pages. So, 'predictionOutput' value likes this:

    {"@odata.type":"#Microsoft.Dynamics.CRM.expando","pageCount":2,"layoutName",....}

     

    My idea is to create a variable 'predOutput' and assign its values from AI model. 

    Then the number of page will be equal to:

    split(split(variables('predOutput'),',"layoutName"')[0],'pageCount":')[1]

     

    Best,

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 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard