Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

MWE

Imagine that you want to simulate a hand stamp on every page in some large documents. It must be an imperfect print, with random page-to-page variations in ink intensity, fading, rotation and blur. Imagine also that stamp content must change with each document.

The traditional solution would be to buy rubber stamps for each document and make stamping and scanning exercises, but besides being expensive, what fun would it be?

A cheaper solution is to insert a PNG or PDF image in every page at some place, but designing each stamp is still a lot of previous work. Moreover, it will be too obviously computer-generated if the stamp is always the same image in the same place on every page, even when the original is a very realistic stamp.

In How to make a realistic old rubber stamp? it is shown that stamps could include LaTeX text and how a fading effect could mimic in part a rubber stamp. Beyond this, I am trying to make the whole stamp in LaTeX (excepting some inner image too complex for coding), with easily configurable content and ink color and with some noise in circle lines, with the help of TikZ library decorations.pathmorphing, transparencies, and text layers. The result is the above image and below dirty slow-witted code.

I find this still a very poor result. Not only because an expert could make a more realistic blur and/or cleaner code and/or faster compilation, but mainly because while thinking what would be a good general purpose LaTeX stamper, I thought of several minimal requirements:

  • pdflatex compatible
  • Highly configurable by a end user (user-defined text contents, ink color, size, central coat of arms)
  • Result compatible with usual PDF viewers (not only Acrobat Reader)
  • Random page-to-page stamp rotation (probably best limited around +/- 30 degrees)
  • Random page-to-page fading. Probably a simple fading of the whole stamp with random orientation (360 degrees) is enough, but it must not affect the overlapping text.
  • Random page-to-page ink intensity (i.e., whole transparency between 0.5 to 0.8)
  • Random page-to-page position between a concrete area (i.e, around +/- 2 cm in the x,y position of page)

Unfortunately I still have very little experience to improve the code significantly, mainly with TikZ. Is this all possible?

Finally, what could be your own desired milestone for a hypothetical stamper package? Making alternate stamps oval or rectangular shapes, for example?

My apologies for the broad question but I think that in this case even a partial answer could be more manageable than a storm of complete answers to isolated problems.

\documentclass{article}
\usepackage{lipsum}
\usepackage{xcolor,pgfplots}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,fadings,positioning,decorations.pathmorphing,fit}
\usetikzlibrary{decorations.text}
\pgfplotsset{compat=1.7} 
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{rotating}

% STAMP CONFIGURABLE CONTENT

\definecolor{stampink}{RGB}{0 34 85}           % Define color old stamp in RGB 
\newcommand\textUp{TOWARD A STAMPER PACKAGE}   % Top label
\newcommand\textDown{Open question}            % Bottom label
\newcommand\textCap{\texttt{\bfseries\today}}                    % Center label
% PDF (name and path) for best result with same RGB that stampink
\newcommand\CoatOfArms{stampcoat.png}  


% STAMP FIXED CODE 
% free hand style of circles stolen from http://tex.stackexchange.com/a/49272/11604
\pgfdeclaredecoration{free hand}{start}
{
  \state{start}[width = +1pt,
                next state=step,
                persistent precomputation = \pgfdecoratepathhascornersfalse]{}
  \state{step}[auto end on length    = 3pt, % 3
               auto corner on length = 3pt, % 3               
               width=+1pt] % 1
  {
    \pgfpathlineto{
      \pgfpointadd
      {\pgfpoint{1pt}{1pt}}
      {\pgfpoint{rand*.25pt}{rand*.2pt}} % good values .2pt aand .15pt
    }
  }
  \state{final}
  {}
}
 \tikzset{free hand/.style={
    decorate,
    decoration={free hand}
    }
 } 
\def\freedraw#1;{\draw[free hand] #1;} 


%CENTRAL STAMP CONTENT
\newcommand\textCenter{
\begin{minipage}{2.2cm}{}
\vspace{-1em}
\centering
\includegraphics[width=1.8cm,height=1.8cm]{\CoatOfArms}\par
\resizebox{2cm}{.205cm}{\textcolor{stampink}{\textCap}}%
\end{minipage}
}

% STAMPER MACRO
\newcommand\Stamper{\resizebox{3cm}{3cm}{ % FINAL SIZE TAMP
\begin{tikzpicture}[opacity=.8,transparency group]
\normalsize\sffamily
% EXTERIOR CIRCLE
\freedraw[color=stampink,opacity=.3,line width=5pt,rotate=0] (0,0.02) circle (3.6cm);
\freedraw[color=stampink,opacity=.5,line width=3pt,rotate=30] (0,0.01) circle (3.6cm);
\freedraw[color=stampink,opacity=.7,very thick,rotate=20] (0,0) circle (3.6cm);
% TOP CIRCULAR LABEL 
\path [opacity=.2,postaction={decorate,decoration={raise=-1.3ex,text along path, 
reverse path,text align=center,
text={|\huge\bfseries\color{stampink}|\textUp}}}] (-31:3.055cm) arc (-31:210:3.055cm);
\path [opacity=.4,postaction={decorate,decoration={raise=-1.7ex,text along path, 
reverse path,text align=center,
text={|\huge\bfseries\color{stampink}|\textUp}}}] (-30.7:3.055cm) arc (-30.7:210:3.055cm);
\path [opacity=.8,postaction={decorate,decoration={raise=-1.5ex,text along path, 
reverse path,text align=center,
text={|\huge\bfseries\color{stampink}|\textUp}}}] (-30:3.05cm) arc (-30:210:3.05cm);
% BOTTOM CIRCULAR LABEL
\path [opacity=.2,postaction={decorate,decoration={raise=-1.2ex,text along path, text align=center,
text={|\huge\bfseries\color{stampink}|\textDown}}}] (210:3.05cm) arc (210:330:3.05cm);
\path [opacity=.4,postaction={decorate,decoration={raise=-.85ex,text along path, text align=center,
text={|\huge\bfseries\color{stampink}|\textDown}}}] (210:3.05cm) arc (210:330:3.05cm);
\path [opacity=.8,postaction={decorate,decoration={raise=-1ex,text along path, text align=center,
text={|\huge\bfseries\color{stampink}|\textDown}}}] (210:3.05cm) arc (210:330:3.05cm);
%INNER CIRCLE AND CENTRAL CONTENT
\freedraw[color=stampink,opacity=.3,line width=4pt,rotate=0] (0.015,0.02) circle (2.5cm) node[scale=1.54] (m) {\textCenter}; 
\freedraw[color=stampink,opacity=.5,line width=3pt,rotate=30] (-0.025,-0.01) circle (2.5cm) node[scale=1.5] (m) {\textCenter}; 
\freedraw[color=stampink,opacity=.7,very thick,rotate=20] (0,0) circle (2.5cm) node[scale=1.52] (m) {\textCenter}; 
\draw[draw=none] 
    [postaction={path fading=north,fill=white!99,opacity=0.6}]
    (-5,-5) rectangle (5,5);%

\end{tikzpicture}}}


\begin{document}

% stamp under text
\vspace{5.5cm}\hspace{8cm}\rotatebox[origin=c]{-30}{\Stamper}\vspace{-5.5cm}

\lipsum[2] 
% stamp over text
\vspace{-2cm}\Stamper

\end{document}

Edit: As stampcoat.pdf cannot be uploaded, the MWE is changed to include a PNG version:

stampcoat.png

This can be changed with any PDF or PNG image with transparent background and the same RGB that the stampink defined color.

share|improve this question
    
@Kundor Thanks for the edit. Much better now! –  Fran Feb 4 '13 at 3:55
    
Did you read up about implementing packages in general? It seems to me that adding the requirement that the package should implement stamps makes it difficult to see the difference between the drawing-specific parts of the implementation and the package interface-specific part of the implementation. As a result, the answers you get will become very specific and won't be of much help to others. –  Marc van Dongen Feb 4 '13 at 13:03
1  
@MarcvanDongen Indeed, the first step is not make the package, but I figured it was important explain the whole set of problems and the ultimate goal to obtain answers in the right direction. We'll see. Anyway it is useful to see if a stamper package is really interesting. –  Fran Feb 5 '13 at 2:02
    
i) It would be much easier just to create a random position generator, which would look already really realistic. ii) In addition, you can rotate about a small random angle. iii) Finally, you can simply change the total intensity of your drawing. This is not so difficult for images created internally with tikz or similar as you exchange colors by lighter ones, e.g. \color{stampink!20!white} and exchange the value 20 with another random variable. –  strpeter Feb 11 '13 at 22:52
    
@Fran Can you write down clearly formulated questions such that it is easier to find out where you got stuck? Remember that I do not have any file called stampcoat.pdf, so I can not fully reconstruct your procedure. –  strpeter Feb 11 '13 at 23:02
show 1 more comment

1 Answer

You could adapt the following example:

\documentclass{article}
\usepackage{background}
\usepackage{lipsum}
\backgroundsetup{%
color={rgb:red,\thepage;green,10},
opacity=0.1*\thepage,
scale=5,
position={0.1*\thepage,-0.1*\thepage},
angle=10*\thepage,
contents={\begin{tikzpicture}\draw(0,0)circle(1)node{A \thepage B};\end{tikzpicture}},
}

\begin{document}
\lipsum[1-100]
\end{document}

If you want it randomised, you have to replace the computations in the code by appropriate computations using a randomizer. The most difficult aspect would be the color, because the color definition isn't parsed by tikz (or so, I haven't quite understood that technique). If you need more complicated computations for example for the color, you could also employ the everypage package, that is used by background package anyway.

share|improve this answer
    
Welcome to TeX.sx! Nice effect! –  Peter Jansson Feb 25 '13 at 18:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.