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

Announcements

News and Announcements icon
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 Moderator 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 2026 Season 1 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 600

#2
Valantis Profile Picture

Valantis 453

#3
11manish Profile Picture

11manish 356

Last 30 days Overall leaderboard