DEV Community

Cover image for How to replicate a PDF template into multiple pages
Rohan "HEXcube" Villoth
Rohan "HEXcube" Villoth

Posted on

How to replicate a PDF template into multiple pages

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
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)