All templates
PDFBeginner
Create PDF from Selected Pages
Robomotion•Updated 9 months ago

Overview
Pulls a chosen range of pages from a source PDF and writes them to a new document. Useful for trimming or sharing parts of a report.
Create PDF from Selected Pages
PDF files may have tens or hundreds of pages depending on the nature of their content. An effective way to handle specific information from these files is to gather it in a separate file. Robomotion's PDF nodes enable users to extract any possible combination of pages and save them in different files for further manipulation.
What Create PDF from Selected Pages can do
- Build defaults (
Core.Programming.Function) — seedsmsg.default_pdf(fixtures/sample.pdf) andmsg.default_dest(fixtures/output) from$Home$. - Input Dialog (
Core.Dialog.InputBox) titledCreate new PDF from selected PDF pages, promptSelect the PDF to extract pages from:, defaultmsg.default_pdf→msg.pdf_path. - Input Dialog with prompt
Page number(s) e.g. 1,3,5-7:, default1,3,5-7→msg.pages_text. - Input Dialog with prompt
Select a folder to save the new PDF file..., defaultmsg.default_dest→msg.destination_folder. - Validate and parse (
Core.Programming.Function,outputs: 2) — checks thatmsg.pdf_pathends in.pdf, expandsmsg.pages_text(singles +a-branges) into a deduped, sortedmsg.selected_pagesarray, and seedsmsg.pages_dir,msg.candidate_path,msg.suffix_idx = 0; invalid input short-circuits toCore.Flow.Stop. - Prepare dirs (
Core.FileSystem.Createonmsg.destination_folder, thenCore.FileSystem.Delete+Core.FileSystem.Createonmsg.pages_dir, allcontinueOnError). - Split per page (
Robomotion.PDFBox.Split,optPerPage: 1, prefixp) — writes one PDF per source page intomsg.pages_dir. - List pages (
Core.FileSystem.List, ascending) →msg.page_files, then pick selected paths (Core.Programming.Function,outputs: 2) — mapsmsg.selected_pagesto the ascending file list intomsg.picked_paths; empty selection goes toCore.Flow.Stop. - Suffix loop (
Core.Flow.Label+Core.FileSystem.PathExistsonmsg.candidate_path+Core.Programming.Function,outputs: 2) — if the candidate exists, bumpmsg.suffix_idxand retry (NewPDFfile_2.pdf,_3, ...); otherwise commit tomsg.output_path. - Merge selected (
Robomotion.PDFBox.Merge) — joinsmsg.picked_pathsintomsg.output_path, thenCore.FileSystem.Deletethe pages scratch dir. - Build done text (
Core.Programming.Function) setsmsg.dialog_text = 'The new file has been saved in: ' + msg.output_path, then a Message Dialog (Core.Dialog.MessageBox,optType: info) titledDone!shows it and the flow stops.
Behind the scenes
- The page-selection grammar (
1,3,5-7— mixed singles and ranges) is expanded inside the Function node: comma split,\d+-\d+regex, dedupe, sort ascending. Pages outside the document range are silently dropped when mapping intomsg.picked_paths. - Suffix handling is explicit: the loop tests
Core.FileSystem.PathExistsonNewPDFfile.pdf, thenNewPDFfile_2.pdf,NewPDFfile_3.pdf, ... so an existing output is never overwritten. - Split-then-merge (one PDF per page, then merge the chosen subset) is used instead of a single range-extract call so arbitrary non-contiguous selections (
1,3,5-7) work uniformly. - Scratch pages under
msg.pages_dirare cleared both before the split (stale run) and after the merge (cleanup).
More pdf templates
See all 9 →- Extract Tables from PDFLocates tables inside a PDF and extracts their rows into structured data. A drop-in stage in any OCR-adjacent pipeline.
- Get Images from PDFExtracts every embedded image from a PDF file into a target directory. Useful for downstream OCR or asset recovery.
- Get Number of Pages in a PDFReports the page count of a PDF file as a single number. A small utility that feeds splitters, paginators, and dashboards.
- Merge PDFsCombines every PDF in a folder into one consolidated document using a reusable merge subflow.
- Merge Two PDFsJoins two PDF files into a single output document — the minimal merge recipe.
- Split PDF by HalfCalculates a midpoint and splits a PDF into two evenly-sized halves. Demonstrates arithmetic on page counts feeding a splitter.