Overview | All Articles | Homepage |
RSS
Keywords: KDE, LaTeX, Linux, Mathematics, Society, University
Planets: Planet Fachschaftsumfeld
2008-04-27 by Thomas Fischer [de]
As promised last time, I'm going to show a small bash script which puts text on existing pdf files.
This bash script uses pdflatex, some styles and auxiliary programs to do its magic.
The script is currently work in progress, thus feedback is welcome.
Once the script is placed somewhere in the path, you can apply it to any pdf document. The scripts parameters are group into three categories:
%d will be replaced by the current date, %p will be replaced with the current page's numberLet me show you some examples:
textonpdf.sh -x 0 -y 27 -w 21 -t '%p' -i myfile.pdf -o output.pdfwill put page numbers (as given by
-t '%p') centered (given a page is 21cm wide) at the bottom of each page (27cm below the top).
As promised, multiple boxes may be specified. The following example puts the current date on the top of each page:
textonpdf.sh -x 5 -y 27 -w 11 -t '%p' -x 2 -w 17 -y 2 \
-t 'File created on \textbf{%d}' -i myfile.pdf -o output.pdf
As you can see, LaTeX commands can be used in the inserted text, as the boxes' content is directly used in the intermediate tex document.
Updated: Finally, a more complex example for a watermark.
First, we create a prefix file, which will be loaded using the -p switch.
\usepackage[scaled]{helvet}
\usepackage[utf8]{inputenc}
\usepackage{rotating}
\usepackage{xcolor}
These packages load Helvetica as font, set the input encoding to UTF-8 (may be different for you), and include the rotating and xcolor package.
Now, we call the script:
textonpdf.sh -x 1 -y 1 -p prefix.tex -w 10 -t \
'\centering\begin{turn}{25}\begin{minipage}{10cm}\centering\bfseries\sffamily\Huge\color{red}Nur für den\\internen Gebrauch\end{minipage}\end{turn}' \
-i test.pdf -o test2.pdf
Here, you can two new things:
First, the prefix file prefix.tex (see above) and include some tex commands into the text at the -t switch.
In the text, there are commands to turn the text by 25 degrees and a minipage of 10cm widths (required for the line break later).
Inside the minipage, all text is centered, set in Helvetica, huge and red.
The text itself is a two lines long and warns you the document is for internal use only.
Using or removing the -l switch makes a difference.
Does it work for you, too? Any bugs or comments? Let me know.
Keywords: LaTeX, Linux
Trackback-URL: http://www.t-fischer.net/blog/20080427_Text_on_PDF_Files
Writing comments is currently not possible. Feel free to write me an email to the address shown on my homepage.
More social bookmarking links than anybody else ;-)![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
Date of Modification: 2009-Feb-21 18:08