Dienstag, 23. Juni 2015

LibreOffice: Adding a draft watermark to exported PDFs

When distributing documents that have not reached final state yet, it may be a good idea to mark them as draft. LibreOffice supports watermarks for this purpose and others (File > Export as PDF... > Watermark). However, the implemenation has some downsides: The color of the watermark text is a green that not everybody may like and the text is vertical, which also does not look too good if you compare it to the watermarks that LaTeX packages produce. Moreover, the user cannot adjust the watermark to his needs, as the settings are hard-coded in LibreOffice's source code...
So, as LaTeX does the job very well, one workaround is to generate a draft watermark using LaTeX and then setting it as the background image of an exported PDF from LibreOffice (another one is setting a background image directly in LibreOffice):
The following code uses the draftwatermark package to adjust and generate a watermark:


\usepackage{lmodern}    % Latin Modern
%\usepackage{tgheros}   % Helvetica
%\usepackage{tgtermes}  % Times
%\usepackage{tgcursor}  % Courier

% adapt default font
%  * serif:      \rmdefault
%  * sans-serif: \sfdefault
%  * monospace:  \ttdefault

% see package documentation for further configuration options

\pagenumbering{gobble} % remove page numbers
\mbox{}                % pdflatex refuses to emit an empty page otherwise

After building the PDF file using pdflatex, you can use the pdftk command line tool to add it as background/watermark to a PDF document exported from LibreOffice (stamp instead of background places the LaTeX document in front of the other):

pdflatex watermark.tex
pdftk in.pdf background watermark.pdf output out.pdf

The source code and some generated PDFs can be found in this tar archive. It also contains a script draft.sh which adds a draft watermark to a PDF document:

./draft.sh in.pdf out.pdf

Keine Kommentare:

Kommentar veröffentlichen