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?
Well, I've come up with a solution using TikZ within a crafted LaTex document.
The result is not exactly the same, but I think it is even nicer:
This required having a tex document with placeholders that will be replaced by the arguments to a sh script.
% file: add_legend.tex
\documentclass{standalone}
\usepackage{graphicx}
\usepackage{tikz}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LaTeX Overlay Generator - Annotated Figures v0.0.1
% Created with (omitted http) ff.cx/latex-overlay-generator/
% If this generator saves you time, consider donating 5,- EUR! :-)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\annotatedFigureBoxCustom{bottom-left}{top-right}{label}{label-position}{box-color}{label-color}{border-color}{text-color}
\newcommand*\annotatedFigureBoxCustom[8]{\draw[#5,thick,rounded corners] (#1) rectangle (#2);\node at (#4) [fill=#6,thick,shape=circle,draw=#7,inner sep=4pt,font=\huge\sffamily,text=#8] {\textbf{#3}};}
%\annotatedFigureBox{bottom-left}{top-right}{label}{label-position}
\newcommand*\annotatedFigureBox[4]{\annotatedFigureBoxCustom{#1}{#2}{#3}{#4}{white}{white}{black}{black}}
\newcommand*\annotatedFigureText[4]{\node[draw=none, anchor=south west, text=#2, inner sep=0, text width=#3\linewidth,font=\sffamily] at (#1){#4};}
\newenvironment {annotatedFigure}[1]{\centering\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (-0.75,-0.75) { #1};\begin{scope}[x={(image.south east)},y={(image.north west)}]}{\end{scope}\end{tikzpicture}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{annotatedFigure}
{\includegraphics[width=1.0\linewidth]{_image_}}
\annotatedFigureBox{0,0}{0.000,0.0}{_letter_}{0,0}%bl
\end{annotatedFigure}
\end{document}
And the sh script:
#!/bin/sh
# Call this script with at least 2 parameters, for example
# sh scriptname <image_file> <letter_of_legend>
cat add_legend.tex | sed "s/_image_/$1/g" | sed "s/_letter_/$2/g" | pdflatex
#rename output to match <letter_of_legend>_<image_file> format
mv texput.pdf $2_$1
#clean up
rm texput.*
exit 0
Finnaly, by calling:
$> ./legend.sh online_gauss.pdf A
the output drawn in "A_online_gauss.pdf"!
Best Answer
I recently became involved in a legal matter, for which I wrote a PDF "Bates-stamping" script,
pdfBatesStamp.sh
.usage excerpt
Full script available for download from pastebin, pdfBatesStamp.sh.