All templates
PDFIntermediate
Get Number of Pages in a PDF
Robomotion•Updated 6 months ago

Overview
Reports the page count of a PDF file as a single number. A small utility that feeds splitters, paginators, and dashboards.
Get Number of Pages in a PDF
While handling PDF files, users may encounter scenarios that require them to extract specific information regarding the files. The available PDF nodes enable users to retrieve various details from PDF files, such as the total number of their pages.
What Get Number of Pages in a PDF can do
Core.Flow.SubFlowdownloads fixtures, then a Function buildsmsg.default_pdfpointing at$Home$/templates/pdf-automation/get-number-of-pages/fixtures/sample.pdf.- Input Dialog titled
Find the number of pages in PDF, messageSelect a PDF file:, defaultmsg.default_pdf→msg.pdf_path. - Branch (
Core.Programming.Function,outputs: 2) — proceed only whenmsg.pdf_pathends in.pdf; otherwiseCore.Flow.Stop. - Function derives
msg.count_diras<pdf dir>\_page_count, thenCore.FileSystem.Delete+Core.FileSystem.Createreset the directory. Robomotion.PDFBox.SplitwithoptPerPage: 1and prefixpwrites one file per page intomsg.count_dir.Core.FileSystem.Listpopulatesmsg.page_files; a Function counts non-directory entries intomsg.page_countand buildsmsg.dialog_text.Core.FileSystem.Deleteremoves the temp dir, thenCore.Dialog.MessageBoxtitledFlow finished running...showsmsg.dialog_text.
Behind the scenes
- Splitting the PDF into single-page files and listing the output directory is a robust way to count pages without relying on metadata that some PDFs omit or misreport.
- The temp directory sits next to the source PDF so the user never has to grant write access to an unfamiliar path; it is cleared before and after the run so repeated executions do not accumulate artefacts.
continueOnError: trueon the delete/create pair makes the reset idempotent — a missing directory on the first run, or a locked file from a previous aborted run, does not abort the flow.Robomotion.PDFBoxexposes page metadata directly on some nodes; if performance matters, swap the split/list pair for a metadata read and keep the dialog wiring intact.