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.

I am currently setting up a serial letter (ie. one letter/same content, multiple recipients). My current script outputs all pages in one, long PDF document. Is there way to make LaTeX generate separate PDFs, one for each letter?

Main TeX document:

% !TEX encoding = UTF-8 Unicode
\documentclass[11pt]{g-brief}
\usepackage[utf8]{inputenc}
\usepackage{ngerman}
\usepackage{enumerate}
\usepackage{eurosym}
\usepackage{lmodern}
\usepackage{textcomp}

\usepackage[arrow, matrix, curve]{xy}

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

\lochermarke
\faltmarken
%\fenstermarken
\trennlinien


\Name                {My Name}
\Strasse             {My Street 123}
\Zusatz              {}
\RetourAdresse       {}
\Ort                 {12345 Whereilive}
\Land                {}

\Telefon             {555-1212}
\Telefax             {555-1313}
\EMail               {some@address.com}

\Unterschrift        {My Name}

\Adresse             {
Some \\ Recipient\\Address}

\Betreff             {Why am I writing to You today?}

\Datum               {\today}
%\IhrZeichen          {} 
%\IhrSchreiben        {}
%\MeinZeichen         {cts 20100506.1}

\Anrede              {Sehr geehrte Damen und Herren,}
\Gruss               {Mit freundlichem Gruss,}{1cm}

\Anlagen             {\emph{Anlage: some other page}}

\newcommand{\BriefAn}[5]
{
  \newpage
  \Adresse{#1 #2\\ #3 \\\\ \textbf{#4}}


  \begin{g-brief}

\shorthandoff{"}

I would like to ask you this
\begin{enumerate}
\item yabber yabber
\item somme foobar
\item more yabber
\item more foobar
\item enough of this already
\end{enumerate}



  \end{g-brief}
}

\begin{document}
\input{Adressen.tex}
\end{document}

\endinput

Adressen.tex contains this:

\BriefAn{Firstname}{Lastname}{Some Street 314}{12345 Somewhere}{m}
\BriefAn{Firstname}{Lastname}{Some Street 314}{12345 Somewhere}{m}
\BriefAn{Firstname}{Lastname}{Some Street 314}{12345 Somewhere}{m}
\BriefAn{Firstname}{Lastname}{Some Street 314}{12345 Somewhere}{m}
share|improve this question
1  
A single run of pdflatex can produce only one PDF file. –  egreg Jan 30 '13 at 15:17
    
But a Single Run of 'pdflatex' may call other instances of itself, so there might be a way. However using pdftk might be easier –  Uwe Ziegenhagen Jan 30 '13 at 19:28
    
What about calling pdftk from pdflatex? (LaTeX is where we can easily get the info about partitioning into pages.) –  Sašo Živanović Jan 30 '13 at 20:50
add comment

1 Answer

You can exploit the write18 facility and invoke pdftk (link for pdftk) from within latex:

\documentclass{article}

\usepackage{filecontents}
%% ----------------- Your addresses here--------------------------
\begin{filecontents*}{Adressen.tex}
\BriefAn{Firstname}{Lastname}{Some Street 314}{12345 Somewhere}{m}
\BriefAn{Firstname}{Lastname}{Some Street 314}{12345 Somewhere}{m}
\BriefAn{Firstname}{Lastname}{Some Street 314}{12345 Somewhere}{m}
\BriefAn{Firstname}{Lastname}{Some Street 314}{12345 Somewhere}{m}
\end{filecontents*}
% ------------------main letter -- letters.tex here--------------------------------
\begin{filecontents*}{letters.tex}
% !TEX encoding = UTF-8 Unicode
\documentclass[11pt]{g-brief}
\usepackage[utf8]{inputenc}
\usepackage{ngerman}
\usepackage{enumerate}
\usepackage{eurosym}
\usepackage{lmodern}
\usepackage{textcomp}

\usepackage[arrow, matrix, curve]{xy}

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

\lochermarke
\faltmarken
%\fenstermarken
\trennlinien


\Name                {My Name}
\Strasse             {My Street 123}
\Zusatz              {}
\RetourAdresse       {}
\Ort                 {12345 Whereilive}
\Land                {}

\Telefon             {555-1212}
\Telefax             {555-1313}
\EMail               {some@address.com}

\Unterschrift        {My Name}

\Adresse             {
Some \\ Recipient\\Address}

\Betreff             {Why am I writing to You today?}

\Datum               {\today}
%\IhrZeichen          {} 
%\IhrSchreiben        {}
%\MeinZeichen         {cts 20100506.1}

\Anrede              {Sehr geehrte Damen und Herren,}
\Gruss               {Mit freundlichem Gruss,}{1cm}

\Anlagen             {\emph{Anlage: some other page}}

\newcommand{\BriefAn}[5]
{
  \newpage
  \Adresse{#1 #2\\ #3 \\\\ \textbf{#4}}


  \begin{g-brief}

\shorthandoff{"}

I would like to ask you this
\begin{enumerate}
\item yabber yabber
\item somme foobar
\item more yabber
\item more foobar
\item enough of this already
\end{enumerate}    
  \end{g-brief}
}

\begin{document}
\input{Adressen.tex}
\end{document}

\endinput
\end{filecontents*}
%----------------------------------------------------------------
% Compile your document
\immediate\write18{pdflatex letters}
%----------------------------------------------------------------
% Split in to individual pages
%\immediate\write18{pdftk letters.pdf burst allow Printing}
\makeatletter
\immediate\write18{pdftk letters.pdf burst allow Printing output letter-page-\@percentchar02d.pdf}
\makeatother
%----------------------------------------------------------------    
\begin{document}
  Check for the individual pages in different files with names \verb|letter-page-<page number>| in the same folder as this \verb|.tex| file.
\end{document}

Compile this with pdflatex. You will get 4 pdf files with names letter-page-<page number> in the same folder.

share|improve this answer
    
Speldid idea - doesn't work for me, though :( I get this in my logfile: runsystem(pdflatex letters)...disabled (restricted). runsystem(pdftk letters.pdf burst allow Printing output letter-page-%02d.pdf).. .disabled (restricted). pdftk is installed and working. –  Christian Jan 31 '13 at 10:10
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.