Merge and split PDF
Goal
Produce new PDF files with exactly the pages the user wants in the order they want, while the originals stay untouched. A good result comes with a page map the user saw first and a check that the page counts add up.
When to use
- Combining several PDFs into one, in a given order.
- Splitting one PDF by chapter, by page ranges or every N pages.
- Extracting, deleting, rotating or reordering pages.
- For assembling a full meeting pack with an index, use
use_skillwithmeeting-pack-assembly. - For other PDF work such as forms or watermarks, use
use_skillwithpdf.
Steps
- Inventory the inputs with
ls. For each PDF get the page count and whether it is encrypted, usingrun_commandwith a PDF library orrun_commandwith a PDF tool that is installed. Check availability before assuming one. - Resolve encryption. A file with an open password needs it from the user via
ask_user. Do not try to break protection. - Write the page map as a plain table: output file, source file, source pages, rotation. Use the PDF's real page index, counted from the first sheet, not the number printed on the page. Show the map and the expected page count of each output.
- Get approval with
ask_user, especially for the order and for any pages dropped. - Create the outputs in a new folder or with a new name, such as
name_merged.pdforname_part1.pdf. Never save over a source. Userun_commandto do the operation. - Verify each output: page count equals the plan, first and last page match the source pages by text sample, and the file opens. Check file size against the sum of the inputs.
- For splits by chapter, find boundaries from the outline or the table of contents rather than guessing, and show the chosen boundaries before cutting.
- Report the output paths and sizes. Offer to compress only if the size is a problem, and say that compression may lower image quality.
- Offer follow-ups only when they fit what the user wanted.
- Add page numbers or a stamp if the merged file is meant for printing or filing.
- Name the outputs with a convention if there are many parts, such as
part01topart12. - Suggest keeping the page map file so the same operation can be repeated.
- Remind the user that sources remain where they were, and can be deleted when the user is satisfied.
- If any output is over a size limit the user mentioned, say so and offer options.
Gotchas
- Printed page numbers and PDF page indexes differ when there are cover pages or roman numeral front matter. The user says page 5, the file means index 9. Confirm which one.
- Merging drops or breaks bookmarks, internal links and form fields in many tools. Tell the user what was lost, and rebuild bookmarks if they are needed.
- Mixed page sizes and orientations print badly. Report them instead of silently scaling.
- Splitting a signed PDF invalidates the signature. Say so before doing it.
- Pages that are scans of a rotated sheet carry a rotation flag, not rotated pixels. Extracting without the flag shows them sideways.
- A split by "every N pages" cuts through the middle of sections. If sections matter, split on the outline instead.
Output
- The page map file path, if one was saved.
- The page map and the list of files written with page counts and sizes.
- A note on anything lost or changed: bookmarks, links, form fields, signatures.
- The untouched sources named as such.
