I have a PDF file that needs a blank page inserted into it every so often. The pattern is unpredictable, so I need a command that will allow me to fit one in wherever necessary.
How can i do this?
I have a PDF file that needs a blank page inserted into it every so often. The pattern is unpredictable, so I need a command that will allow me to fit one in wherever necessary.
How can i do this?
From http://blog.chewearn.com/2008/12/18/rearrange-pdf-pages-with-pdftk/
pdftk A=src.pdf B=blank.pdf cat A1 B1 A2-end output res.pdf
Hope you like this script, just save it as pdfInsertBlankPageAt.sh
, add execute permissions, and run.
./pdfInsertBlankPageAt 5 src.pdf res.pdf
#!/bin/bash
if [ $# -ne 3 ]
then
echo "Usage example: ./pdfInsertBlankPageAt 5 src.pdf res.pdf"
exit $E_BADARGS
else
pdftk A=$2 B=blank.pdf cat A1-$(($1-1)) B1 A$1-end output $3
fi
cat A1 B1 A2-end
means that the output file will contain the first page of document A (src.pdf
) followed by the first page of document B (blank.pdf
) followed by the rest (pages 2 to end) of document B. This operation is called concatenation, Linux cat
is very often used to display text, but it is interesting when used with more than one argument.
To create blank.pdf
, see How do I create a blank PDF from the command line?
For anyone just looking to add a single blank page to the end of a PDF, I used the already linked question How do I create a blank PDF from the command line? to create a blank.pdf
file and merge it with my existing pdf using pdfunite
:
pdfunite input.pdf blank.pdf output.pdf
If using pdfjam is an option:
pdfjam --outfile output.pdf input.pdf "-20,{},21-"
In pdfjam, {}
inside range specifications is interpreted as a blank page, so this command inserts a blank page between pages 20 and 21.
Here is the steps I used to have blank page after every page of my Pdf file with Pdftk in Ubuntu
1-Install pdftk if you haven't already
sudo apt-get install pdftk
2-Create a blank PDF file named blank.pdf. You can use the convert command from the ImageMagick package to create a blank image and then convert it to PDF. Run the following commands:
sudo apt install imagemagick
convert -size 595x842 xc:white blank.jpg
convert blank.jpg blank.pdf
if you got security policy error, open the policy.xml file using a text editor with root privileges. For example, you can use the following command to open it with the nano editor:
sudo nano /etc/ImageMagick-6/policy.xml
Change the value of the rights attribute from "none" to "read|write" for PDF. The modified line should look like this:
<policy domain="coder" rights="read|write" pattern="PDF" />
3- Now navigate to the directory where your PDF file is located then use the following commands
pdftk input.pdf burst output burst_output%d.pdf
pdftk $(for f in burst_output*.pdf; do echo -n "$f blank.pdf "; done) cat output final.pdf
put the name of your input file instead of "input".
Now your final.pdf is ready! You can delete the splitted pages after this.
echo "" | ps2pdf -sPAPERSIZE=a4 - pageblanche.pdf
– remjg May 31 '14 at 17:42