All templates
PDFAdvanced
Split PDF into Parts
Robomotion•Updated 6 months ago

Overview
Divides a PDF into N equal-sized slices and writes each part out as its own file. A general-purpose chunker for large documents.
Split PDF into Parts
As PDF files are a widespread way to share information, a common requirement is splitting them into parts for further processing. Robomotion allows users to split PDF files by a set number of pages without struggle.
What Split PDF into Parts can do
Core.Flow.SubFlowDownload Fixturespreps sample data, thenCore.Programming.Functionbuildsmsg.default_pdf = global.get('$Home$') + '/templates/pdf-automation/split-pdf-into-parts/fixtures/sample.pdf'.- Input Dialog titled
Split a PDF file, messageSelect a PDF file to split:, defaultmsg.default_pdf->msg.pdf_path. - Input Dialog titled
Split a PDF file, messageSpecify the number of pages to split by:, default3->msg.n_text. - Validate (
Core.Programming.Function,outputs: 2) — requires a.pdfpath and integern >= 1; setsmsg.pages_per_part,msg.directory,msg.pages_dir = <dir>/_pages_<stamp>,msg.split_output_dir = <dir>/parts_<stamp>; failure goes toCore.Flow.Stop. Core.FileSystem.Create(directory,continueOnError) onmsg.pages_dir, thenRobomotion.PDFBox.Split(optPerPage: 1, prefixp) bursts the source intomsg.pages_dir.Core.FileSystem.List(optAbsolutePath: true,optSort: 'ascend') ->msg.page_files; a Function filters out dirs, sorts by name and packs paths intomsg.chunksof sizemsg.pages_per_part.Core.FileSystem.Createonmsg.split_output_dir, thenCore.Flow.GoTointo theLoop Startlabel that runsCore.Programming.ForEachovermsg.chunks->msg.current_chunk/msg.current_index.- Each iteration calls
Core.Flow.SubFlowMerge ChunkthenCore.Flow.GoToback toLoop Start; when exhausted,Core.FileSystem.Deletecleansmsg.pages_dir, buildsmsg.dialog_textand showsCore.Dialog.MessageBoxtitledFlow ran successfully!.
Behind the scenes
- The timestamped
_pages_<stamp>andparts_<stamp>directories are siblings of the source PDF, so repeated runs never clobber each other and the per-page staging area is easy to clean up after merging. - Splitting is done in two passes: burst to one file per page with
Robomotion.PDFBox.Split, then merge slices ofmsg.pages_per_partpages via theMerge Chunksubflow. This keeps the loop body trivial and letsCore.FileSystem.Listdrive the chunking order. - The final message points the user at
msg.split_output_dirrather than individual file names because the merge subflow is responsible for its own naming scheme.