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:

\documentclass[a4paper]{article}

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

% adapt default font
%  * serif:      \rmdefault
%  * sans-serif: \sfdefault
%  * monospace:  \ttdefault
%\renewcommand*\familydefault{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{draftwatermark}
% see package documentation for further configuration options
\SetWatermarkText{Draft}
\SetWatermarkLightness{0.75}
\SetWatermarkScale{1.2}


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

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