# Include pdf at the end of a document

I have the following code:

\documentclass{book}
\usepackage{pdfpages}

\begin{document}

\chapter{chap1}
Some text.

more text
\chapter{chap2}
even more text

\end{document}


I would like that myfirstfile.pdf and mysecondfile.pdf would be printed at the end of the document, after chap1 and chap2. Any help?

Thanks!

You could use \AtEndDocument for that.

\documentclass{book}
\usepackage{pdfpages}
\begin{document}

\chapter{chap1}
Some text.

more text
\chapter{chap2}
even more text

\end{document}


As for your question in the comment: you can also do

\documentclass{book}
\usepackage{pdfpages}
\AtEndDocument{\includepdf[#1]{#2}}}
\begin{document}

\chapter{chap1}
Some text.