Monday, 14 July 2008

Latex goodie - How to watermark things in Latex/PDFLatex

I have been having problems since ever when trying to distribute some content to people and keeping track of the NDAs I make them sign. A sound solution (good but not really impossible to break) is to watermark the documents before sending. Then if you detect it in the wrong hands, you can ate least trace who did it.

I had for a long time a code to do this, but the real problem was that this code was actually in TeX, meaning that to make it appear in a PDF I have to convert from dvi to ps and then to pdf. I real pain, plus you finish loosing all the goodies from pdflatex, in term of hyperref.

I found a site[1], and with his instructions I managed to produce my own code to put the copyright watermark in my pdflatex documents, here it is:

\usepackage{graphicx,type1cm,eso-pic,color}

\makeatletter
\setlength{\@tempdimb}{.5\paperwidth}%
\setlength{\@tempdimc}{.5\paperheight}%
\setlength{\unitlength}{1pt}%
\put(\strip@pt\@tempdimb,\strip@pt\@tempdimc){%
\makebox(0,0){\rotatebox{45}{\textcolor[gray]{0.95}%
{\fontsize{3cm}{3cm}\selectfont{Final Version}}}}%
\makebox(-100,-300){\rotatebox{45}{\textcolor[gray]{0.95}%
{\fontsize{2cm}{2cm}\selectfont{Internal Use}}}}
\makebox(-500,-0){\rotatebox{90}{\textcolor[gray]{0.95}%
}%
}
\makeatother

You should put this code in your preamble, and it will put a watermark in all your pages. You can change the texts and their positions quite easily, just try it.

[1]- http://filoxus.blogspot.com/2008/01/how-to-insert-watermark-in-latex.html

Anonymous said...

Works exactly the way I need it - great job, thanks a lot!

Habi said...

thanks, i just used this for a progress repord i had to hand in.

Anonymous said...

you should also be able to use

\usepackage{draftwatermark}

this single line does all the work and is compatible with pdflatex. size and brightness can be set like this

\SetWatermarkLightness{ 0.95 }
\SetWatermarkScale{ 5 }

this scales the watermark to the whole page. et voila 3 pretty lines and all work is done.

have fun!

Jean E. Martina said...

How do you change the text when using \usepackage{draftwatermark} ?

This is why I don't use that.....

Anonymous said...

Just use:

\SetWatermarkText{my text}

Life can be so easy. But learning how to script tex is also fun :-)

bth said...

Thanks! Very useful.

Unknown said...

I really wanted to use the draftwatermart, but found that i didn't support color. the watermark package does not use transparency by default, and transparency is not working with dvi files; ordinary latex, that is.

So, to be able to use a "watermark" regardless, I made the following in the preamble:

\usepackage{ifpdf}
\usepackage{color}%
\usepackage{transparent}%
\usepackage{watermark}%
\newcommand{\wmtext}{\huge\textsc{PRELIMINARY DRAFT for
CATS2010}}
\ifpdf
\watermark{%
\raisebox{-0.5\textheight}{%
\parbox{\linewidth}{\centering
\rotatebox{30}{%
\color{red}\transparent{0.4}\wmtext}%
} %
}%
} %
\else
\watermark{%
\raisebox{-0.5cm}{%
\rotatebox{5}{%
\color{red}\wmtext}%
}%
}%
\fi

Anonymous said...

Thanx

KC7HP said...

draftwatermark package crashes my TeX with too much memory use. Morton's code works fine. I augmented with 'anysize' package to crank the watermark larger, replacing text line with:

\newcommand{\wmtext}{\fontsize{90}{80}\selectfont DRAFT}