11

I'm thinking of moving from Crystal Reports to a LaTeX based solution, but it's a requirement to be able to make a pdf that conforms to a pre-printed layout (in the company I work we use pre-printed invoices, so they can be filled manually or printed).

Is there a way to do this with latex? i should need to define:

  • the maximum width of a field.
  • the position of this field.
  • the paper size in milimeters (there are printed checks too!)
Speravir
  • 19,491
  • 1
    Are you looking for something like this: http://tex.stackexchange.com/questions/108374/how-can-i-construct-a-page-layout-with-framed-boxes/108391#108391, that allows you to call macros for filling in the blanks on a pre-printed form? – Steven B. Segletes Feb 24 '14 at 19:14
  • 3
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Speravir Feb 24 '14 at 19:27
  • 1
    this is certainly possible, but you do need to make sure that the printer you use places images reliably within tight tolerances. it may be easier to replicate the "background" form either with (la)tex or as an image, and overlay the data, printing both the form and the data at the same time, which would guarantee accurate alignment. (been doing this for years, though with plain tex, not latex.) – barbara beeton Feb 24 '14 at 19:48
  • 1
    It is not terribly clear what you are trying to do. Are you trying to fill out an existing form or replicate one? I'm guessing the second. That's not difficult although it can be fiddly. You can also set it up as a fillable form which you can complete in a suitable viewer (but not all viewers will let you save the result though some certainly will) or print to complete by hand. The best method depends partly on how many times you expect to reuse a given form. Imposing data over a background might be easiest for a one-off but not easiest if you expect to need the same form again tomorrow. – cfr Feb 24 '14 at 22:11
  • 1
    No duplicate but related somehow: Fill in boxes for forms in TikZ. – Tobi Feb 25 '14 at 00:24
  • well my main issue is with defining the page size in milimeters.

    I have a pre printed paper (I am able to fill the form by hand). But I want to fill it with my printer... In @Harish Kumar's answer I can see how to place a specific field anywhere I want.

    For example: I need to configure the generated pdf to be 10cm x 5cm (real size of paper)

    – Mateo Torres Feb 25 '14 at 20:12

3 Answers3

10

I usually provide registration forms for our workshops in pdf format and also latex code to fill in data: Let us first have a sample Registration form (paper size-letterpaper):

First page (form-0):

enter image description here

Second page (form-1):

enter image description here

Now the code:

\documentclass[letterpaper]{article}% ensure identical page size
\usepackage[charter]{mathdesign}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usepackage[linkbordercolor={0 0 0},colorlinks=true,linkcolor=magenta]{hyperref}
\newcommand{\setfont}[2]{{\fontfamily{#1}\selectfont #2}}
\newcommand{\mycolor}[1]{\color{NavyBlue}{#1}}

\pagestyle{empty}
\begin{document}
% Page 1
\begin{tikzpicture}[remember picture,overlay]
    \node at (current page.center) {\includegraphics{form}};
    \begin{scope}[shift={(current page.south west)},every node/.style={anchor=base west}]
        % Grid to help find the positions (remove in final version)
        \draw [help lines,xstep=.2,ystep=.2,very thin] (0,0) grid (current page.north east); % if you want finer grid
        \draw [help lines,xstep=1,ystep=1,thick] (0,0) grid (current page.north east);
        \draw [help lines,very thick] (0,0) grid [step=5cm] (current page.north east);
        \foreach \x in {0,...,21} { \node [anchor=north] at (\x,1) {\x}; }
        \foreach \y in {0,1,...,27} { \node [anchor=east] at (1,\y) {\y}; }
        % Comment up to here in final version
        \node at (8.5cm,21.79cm) {\mycolor{\textbf{\vrule width 12pt height 1.5pt\hspace{.08cm} \vrule width 12pt height 1.5pt \,\, Harish Kumar}}};
        \node at (7.8cm,20.93cm) {\mycolor{\textbf{Degree}}};
        \node at (7.8cm,20.1cm) {\mycolor{\textbf{Designation, Department}}};
        \node at (7.8cm,19.27cm) {\mycolor{\textbf{XX years}}};
        \node at (7.8cm,18.43cm) {\mycolor{\textbf{XXXXX XXXXX}}};
        \node at (7.8cm,17.61cm) {{\textbf{\href{mailto:yourmail@something.com}{\texttt{yourmail@something.com}}}}};
        \node at (7.8cm,16.8cm) {\mycolor{\textbf{Dr. Harish Kumar}}};
        \node at (7.8cm,15.95cm) {\mycolor{\textbf{Designation, Department}}};
        \node at (7.8cm,15.13cm) {\mycolor{\textbf{Institute}}};
        \node at (7.8cm,14.3cm) {\mycolor{\textbf{XXX XXX}}};
        \node at (8.5cm,13.5cm) {\mycolor{\textbf{$\checkmark\,\,\,\quad$ \vrule width 12pt height 2pt }}};
        \node at (8.87cm,12.69cm) {\mycolor{\textbf{\vrule width 12pt height 2pt $\quad\,\,\,\checkmark$}}};
        \node at (3.7cm,11.83cm) {\mycolor{\textbf{XXXXX}}};\node at (12.2cm,11.83cm) {\mycolor{\textbf{\today}}};
        \node at (3.7cm,11cm) {\mycolor{\textbf{Your Bank}}}; \node at (12.3cm,11cm) {\mycolor{\textbf{Here}}};
        \node at (15.4cm,9cm) {\setfont{frc}{\color{Blue}{Harish Kumar}}};
    \end{scope}
\end{tikzpicture}
\clearpage
% Page 2
\begin{tikzpicture}[remember picture,overlay]
    \node at (current page.center) {\includegraphics{form}};
    \begin{scope}[shift={(current page.south west)},every node/.style={anchor=base west}]
        % Grid to help find the positions (remove in final version)
        \draw [help lines] (0,0) grid (current page.north east);
        \draw [help lines,thick] (0,0) grid [step=5cm] (current page.north east);
        \foreach \x in {0,...,21} { \node [anchor=north] at (\x,1) {\x}; }
        \foreach \y in {0,1,...,27} { \node [anchor=east] at (1,\y) {\y}; }
        % Comment up to here in final version
        %
        \node at (3.4cm,21.64cm) {{\mycolor{PEC}}};
        \node at (3.4cm,20.8cm) {{\mycolor{\today}}};
        \node at (15.9cm,19.55cm) {\setfont{frc}{\color{Blue}{Harish Kumar}}};
        \node at (5.68cm,16.74cm) {\vrule width 12pt height 1pt \hspace{.08cm} \vrule width 12pt height 1pt \hspace{.2cm} \setfont{pzc}{\mycolor{\Large Harish Kumar}}};
    \end{scope}
\end{tikzpicture}
\clearpage
\end{document}

You get this:

enter image description here

Grid is provided just for making it easy to locate the exact coordinates. In the final form comment these lines:

    \draw [help lines] (0,0) grid (current page.north east);
    \draw [help lines,thick] (0,0) grid [step=5cm] (current page.north east);
    \foreach \x in {0,...,21} { \node [anchor=north] at (\x,1) {\x}; }
    \foreach \y in {0,1,...,27} { \node [anchor=east] at (1,\y) {\y}; }
    % Comment up to here in final version

to get:

enter image description here

Note: The blank form which I used above is typeset on letterpaper. Hence in the tex code, I have used the same size. Use appropriate paper size in your tex code ( same as your pre-printed paper).

  • this almost answer the question. It helped me to know how to place a field anywhere I want.

    What about the page size?

    – Mateo Torres Feb 25 '14 at 20:17
  • 1
    @Maluchi: Well, the example code has letterpaper, but you could use the package geometryand set up arbitrary sizes. – Speravir Feb 25 '14 at 20:22
  • 1
    @Maluchi I have added a note below. –  Feb 25 '14 at 22:25
  • If OP does not know how to set the page size, OP is not ready to implement a full solution. Sounds like you are asking for trouble. – Mica Feb 26 '14 at 02:15
  • I searched on my own about the paper size, just asked for a complete answer, now it is tyvm! :) – Mateo Torres Feb 26 '14 at 13:25
  • @Maluchi Glad it hepled. Please feel free to ask any clarifications if any :) –  Feb 26 '14 at 13:28
  • @user11232 How do I make ----- {\includegraphics{form}} ---- such forms those can be included in Latex Document? – Optimight Jul 07 '18 at 04:54
6

I have done this a few times, since my handwriting is soooo bad. I mostly use the textpospackage, lpic was also very helpful.

  • Here's an example for a body organ donation passport: donation
  • a template to fill the Deutsche Bahn railroad form: deutschebahn
  • a contract for a used bike, which uses the lpic package: bike

Here's the code for the last one. It requires the download of the sale contract from contract example (slightly different from the one I originally used)

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[left=0cm,right=0cm,top=0cm,bottom=0cm]{geometry}
\usepackage{graphicx}
\usepackage{lpic}
\setlength{\parindent}{0pt}
\begin{document}
\begin{lpic}[]{kaufvertragprivat(0.999)} % coords(20)
\lbl[t]{41,248;\textcolor{black}{\small \textbf{Max Mustermann}}}
\lbl[t]{130,248;\textcolor{black}{\small \textbf{Martina Musterfrau}}}
\lbl[t]{55,240;\textcolor{black}{\small \textbf{Musterstr. 2, 12345 Musterstadt}}}
\lbl[t]{140,240;\textcolor{black}{\small \textbf{Musterweg 23q, 12345 Musterstadt}}}
\lbl[t]{50,230;\textcolor{black}{\small \textbf{Personalausweis, 1234567890}}}
\lbl[t]{40,160;\textcolor{black}{\small \textbf{Oranje}}}
\lbl[t]{44,150;\textcolor{black}{\small \textbf{Hollandrad}}}
\lbl[t]{41,140;\textcolor{black}{\small \textbf{28 Zoll}}}
\lbl[t]{45,131;\textcolor{black}{\small \textbf{schwarzblau}}}
\lbl[t]{40,122;\textcolor{black}{\small \textbf{12345}}}
\lbl[t]{40,100;\textcolor{black}{\small \textbf{Beleuchtung}}}
\lbl[t]{41,95;\textcolor{black}{\small \textbf{Gepäckträger}}}
\lbl[t]{41,90;\textcolor{black}{\small \textbf{Schutzbleche}}}
\lbl[t]{39,85;\textcolor{black}{\small \textbf{Kopfstütze}}}
\lbl[t]{42,80;\textcolor{black}{\small \textbf{mehr Zubehör}}}
\lbl[t]{42,75;\textcolor{black}{\small \textbf{mehr Zubehör}}}
\lbl[t]{42,70;\textcolor{black}{\small \textbf{mehr Zubehör}}}
\lbl[t]{60,59;\textcolor{black}{\small \textbf{Musterstadt, den \today}}}
\lbl[t]{167,71;\textcolor{black}{\Large \textbf{--1234--}}}
\lbl[t]{113,83;\textcolor{black}{\Large X}}
\lbl[t]{113,121;\textcolor{black}{\Large X}}
\lbl[t]{113,116;\textcolor{black}{\Large X}}
\lbl[t]{113,116;\textcolor{black}{\Large X}}
\lbl[t]{113,126;\textcolor{black}{\Large X}}
\lbl[t]{113,150;\textcolor{black}{\Large X}}
\lbl[t]{113,155;\textcolor{black}{\Large X}}
\end{lpic}
\end{document}

example as png

Uwe Ziegenhagen
  • 13,168
  • 5
  • 53
  • 93
  • In the example you use option t for "top" and it is more appropriate to use no option or [bl] most of the time (You will see the difference if you will need to rescale it.) – Anton Petrunin Nov 10 '15 at 20:43
3

I appreciate the folks who reach for TikZ, nothing wrong with that, but I'll also note that a LaTeX picture environment will also place text anywhere on a page perfectly well.

Jim Hefferon
  • 4,476