I've been using poppler for command line operations on PDFs, like split, merge, conversions, etc., as part of my workflow. My usual use-case is merging PDFs generated from SVGs, like described here in my article on creating multipage PDF documents from SVGs. Using commands for stuff like this can improve efficiency and productivity, whereas most GUI based methods would've made this process more time consuming and repetitive. So, when I found my significant other manually duplicating inner pages for her Amazon KDP notebook template, I set out to find a command to automate it.
Surprisingly, I couldn't find a built-in method on any CLI tool to do this directly. So, I used my Google-Fu and got this two liner working:
for i in {1..120}; do cp template.pdf template-$i.pdf; done
pdfunite template-*.pdf merged.pdf
The first command creates 120 copies of the template. Adjust the number as per your need. The second one then merges all these copies as pages into one PDF file. Make sure you have poppler-utils
installed for pdfunite
command to work. Windows users need to use a bash compatible shell like PowerShell or a Linux distro through WSL.
Credits & Sources
- Cover image from directory pages by Igor Dresjan A.P. on Unsplash
- Linux / UNIX: Run Command a Number of Times In a Row
- Automating the tedious with loops
- How do I duplicate pages within PDF files automatically? - Solution with for loop
- How do I duplicate pages within PDF files automatically? - Solution with pdfunite
Top comments (0)