All templates
PDFAdvanced
Split PDF by Half
Robomotion•Updated 6 months ago

Overview
Calculates a midpoint and splits a PDF into two evenly-sized halves. Demonstrates arithmetic on page counts feeding a splitter.
Split PDF by Half
Apart from dividing PDF files using a user-defined splitting point, Robomotion enables the implementation of fully automatic logic that doesn't require user input, like always splitting PDF files in half.
What Split PDF by Half can do
- Build default path (
Core.Programming.Function) — setsmsg.default_pdfto the bundledsample.pdfunder$Home$/templates/pdf-automation/split-pdf-by-half/fixtures. - Input Dialog titled
Split a PDF by half, messageSelect a PDF file to split:, defaultmsg.default_pdf→msg.pdf_path. - Branch On Cancel (
Core.Programming.Function,outputs: 2) — routes toCore.Flow.Stopunlessmsg.pdf_pathends with.pdf. - Derive Paths (
Core.Programming.Function) — splits the file path intomsg.directoryand buildsmsg.split_output_diras<directory>\split_halves_<timestamp>. - Get Page Count / Compute Half (
Core.Flow.SubFlow) — populatemsg.page_countandmsg.half. - Plan Split (
Core.Programming.Function,outputs: 2) — stops whenpage_count < 2; otherwise setsmsg.custom_pages = [msg.half + 1]. - Ensure Split Dir (
Core.FileSystem.Create,optType: directory,continueOnError: true) formsg.split_output_dir. - Split At Midpoint (
Robomotion.PDFProcessor.Core.Split) —inPDFPath: msg.pdf_path,inDir: msg.split_output_dir,optCustomPages: msg.custom_pages. - Build Done Text +
Core.Dialog.MessageBox(info, titleFlow has been completed!) showing the output directory.
Behind the scenes
- For odd
msg.page_count,msg.half = (count - 1) / 2, so the second half gets the extra page. Flip the subflow if you prefer the opposite convention. page_count < 2short-circuits toCore.Flow.StopinPlan Split— there's no separate handling for0or1-page PDFs.Ensure Split Dirruns withcontinueOnError: trueso re-running the flow against an existing timestamped directory doesn't fail.