cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
nana001
Advocate I
Advocate I

Number of pages in a PDF file

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

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User
Super User

@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.

View solution in original post

9 REPLIES 9
abm
Super User
Super User

Hi @nana001 

 

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

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials

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
Frequent Visitor

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

Paulie78
Super User
Super User

@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.

Anonymous
Not applicable

It works. Thank you.

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

Frederico
Advocate I
Advocate I

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
Frequent Visitor

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

 

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 ?  

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Top Solution Authors
Users online (3,779)