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
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}")
**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
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.