1

I'd like to generate a bulk letter with datatool and include a different pdf for each row. Can this be done with pdfpages?

\documentclass[paper=a4]{scrlttr2}

\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{pdfpages}
\setmainlanguage[babelshorthands=true]{german}
\usepackage{datatool}
\KOMAoptions{fromalign=right,%
fromemail,
foldmarks=off,
enlargefirstpage=on,
fromlogo=true
}
\setkomavar{fromname}{Name}
\setkomavar{signature}{signatur}
\setkomavar{fromemail}{[email protected]}
\setkomavar{fromaddress}{From}
\setkomavar{date}{5. Juni 2024}

\DTLnewdb{mitglieder}
\DTLnewrow{mitglieder}%
\DTLnewdbentry{mitglieder}{Datei}{lorem_ipsum.pdf}%

\begin{document}
\DTLforeach*{mitglieder}{\datei=Datei}{%
  \begin{letter}{Adresse}
    \setkomavar{subject}{Test}

    \opening{Hallo,}

    Text

    \closing{Mit freundlichen Grüßen}
    \encl{Anhang}
  \end{letter}
  \includepdf[pages=-]{\datei}}
\end{document}
New contributor
tobidope is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1 Answer 1

1

Looks good to me. What's not working?

Here is a complete MWE, including a database.

\documentclass[paper=a4]{scrlttr2}

\begin{filecontents}{my.db}
FirstName,LastName,Attachment
Michelle,Johnson,example-image.pdf
James,Smith,example-image-a.pdf
Mary,Wright,example-image-b.pdf
\end{filecontents}

\usepackage{mwe}
\usepackage{pdfpages}
\usepackage{datatool}
\DTLloaddb{members}{my.db}

\begin{document}
\begin{DTLenvforeach}{members}{%
    \firstName=FirstName,
    \lastName=LastName,
    \attachment=Attachment}
  \begin{letter}{%
      \firstName\ \lastName}

    \opening{Dear \firstName\ \lastName,}
    
    \encl{\attachment}
  \end{letter}
  \includepdf{\attachment}
\end{DTLenvforeach}

\end{document}
1
  • Maybe I did include a not existing pdf file (╯‵□′)╯︵┻━┻
    – tobidope
    Commented 2 days ago

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .