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 / Error Message for Extr...
Power Automate
Answered

Error Message for Extract PDF file pages into new PDF

(1) ShareShare
ReportReport
Posted on by 73
Hey there,
 
I tried to splits PFD files in one folder to each and it didn't finish the execution and then stopped. So I only have partial of PDF file split. (see below)  
 
As below, I tried to extract all PDF stayed in PAD PDF 0 folder (in yellow) and split each of those PDF files to each per page int 'PAD PDF 1' folder naming with variable name without extension (in yellow) , but got below error message. 
 
Would you help to take a look into that issue? Thanks!
 
 
 
There are total 19 pages in 9-26 BOL.PDF, but it only got 4 splits. 
 
I have the same question (0)
  • Suggested answer
    Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at
    Hi,
     
    You may try the below code:
     
    Code:(Copy and paste the below code into your power automate desktop designer screen):
    **REGION Get No of pages in pdf
    Folder.GetFiles Folder: $'''C:\\Boot\\SP File''' FileFilter: $'''*.pdf''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> PDFFiles
    
    LOOP FOREACH PDFFile IN PDFFiles
        SET NumberOfPages TO 0
        LOOP WHILE ($'''True''') = ($'''True''')
            Pdf.ExtractPages PDFFile: PDFFile PageSelection: NumberOfPages + 1 ExtractedPDFPath: $'''C:\\Boot\\pdf\\%PDFFile.Name%''' IfFileExists: Pdf.IfFileExists.AddSequentialSuffix ExtractedPDFFile=> ExtractedPDF
            ON ERROR PageOutOfBoundsError
                GOTO Finish
            END
            Variables.IncreaseVariable Value: NumberOfPages IncrementValue: 1
        END
        LABEL Finish
    
    END
    **ENDREGION
    
     
    Screenshot for your reference:
     
    Thanks,
    Deenuji Loganathan 👩‍💻
    Power Automate Desktop Community Champion 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and like my suggestion ❤️  Your feedback supports future seekers 🚀
  • Verified answer
    VishnuReddy1997 Profile Picture
    2,656 Super User 2025 Season 2 on at
     
    Please find the below solution.
     
     
    PAD Code:
     
    Folder.GetFiles Folder: $'''C:\\Desktop\\Power Automate Desktop\\Practice\\PDF\\PAD PDF 0''' FileFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> PDF_Files
    LOOP FOREACH CurrentItem IN PDF_Files
        # Script to Count Number of pages in PDF
        @@copilotGeneratedAction: 'False'
    Scripting.RunPowershellScript.RunPowershellScript Script: $'''Python \"C:\\Desktop\\PDFPagesCount.py\" \"%CurrentItem.FullName%\"''' ScriptOutput=> PDFPagesCount ScriptError=> ScriptError2
        Text.ToNumber Text: PDFPagesCount Number=> PDFPagesCount
        LOOP LoopIndex FROM 1 TO PDFPagesCount STEP 1
            Pdf.ExtractPages PDFFile: CurrentItem PageSelection: LoopIndex ExtractedPDFPath: $'''C:\\Desktop\\Power Automate Desktop\\Practice\\PDF\\PAD PDF 1\\%CurrentItem.NameWithoutExtension%.pdf''' IfFileExists: Pdf.IfFileExists.AddSequentialSuffix ExtractedPDFFile=> ExtractedPDF
        END
    END
    
     
    Python Code:
     
    Please save the code as .py file as use it in Powershell script action.
     
    import fitz  # PyMuPDF
    import sys
    
    def count_pages(pdf_path):
        pdf_document = fitz.open(pdf_path)
        num_pages = pdf_document.page_count
        return num_pages
    
    if __name__ == "__main__":
        if len(sys.argv) != 2:
            print("Usage: python count_pages_pymupdf.py <pdf_path>")
            sys.exit(1)
    
        pdf_path = sys.argv[1]
        num_pages = count_pages(pdf_path)
        print(f"{num_pages}")
     
    (Note:- if you got your solution you can mark as solution and gives kudos)
     
    Thanks & Regards
    Vishnu Reddy
  • xuyinaoyixue1 Profile Picture
    73 on at
    Thank you so much, VishnuReddy1997 and Deenuji_Loganathan_, you both solved my problem! Thanks!

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

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard