0

I have the following code:

\documentclass{book}
\usepackage{pdfpages}

\begin{document}

\chapter{chap1}
Some text.
\includepdf[pages={-},pagecommand={\thispagestyle{headings}},scale=0.7]{myfirstfile.pdf}

more text
\includepdf[pages={-},pagecommand={\thispagestyle{headings}},scale=0.7]{mysecondfile.pdf}
\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!

2

You could use \AtEndDocument for that.

\documentclass{book}
\usepackage{pdfpages}
\AtEndDocument{\includepdf[pages={-},pagecommand={\thispagestyle{headings}},scale=0.7]{example-image-a}
\includepdf[pages={-},pagecommand={\thispagestyle{headings}},scale=0.7]{example-image-b}}
\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}
\newcommand{\AddGraphicsAtEnd}[2][pages={-},pagecommand={\thispagestyle{headings}},scale=0.7]{%
\AtEndDocument{\includepdf[#1]{#2}}}
\begin{document}

\chapter{chap1}
Some text.
\AddGraphicsAtEnd{example-image-a}


more text
\chapter{chap2}
even more text
\AddGraphicsAtEnd{example-image-b}
\end{document}

i.e. just accumulate the stuff you want to put at the end.

  • Thanks! And is there anyway to renew includepdf command to do that by default? I mean, without actually writing \AtEndDocument everytime there is an includepdf command. – Alejandro Fernandez-Montes Sep 3 '18 at 17:46
  • @AlejandroFernandez-Montes Sure. I added something along those lines to my answer. – marmot Sep 3 '18 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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