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

7 REPLIES 7
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 blogPower 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.

View solution in original post

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

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,419)