4

I want to extract the two or three last pages from a beamer produced pdf respecting the original format.

I have no idea how to select the two last pages and witch documentclass to use to respect the original format : both beamer and article go wrong.

\documentclass{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages=last]{file.pdf}
\end{document}
Tarass
  • 16,912

1 Answers1

5

Here is a solution:

\documentclass{article}
\usepackage{pdfpages}
\usepackage{xparse}
\usepackage{l3graphics}

\ExplSyntaxOn \NewDocumentCommand\settotalpagestomacro{mm}{\graphics_get_pagecount:nN {#1}#2} \ExplSyntaxOff \usepackage{xfp}

\NewDocumentCommand\includelastpages{O{1}m}{% \bgroup% \settotalpagestomacro{#2}\lastpage% \edef\prevlastpage{\fpeval{max(1,\lastpage-#1+1)}}% \includepdf[pages=\prevlastpage-\lastpage,fitpaper]{#2}% \egroup% }

\begin{document} \includelastpages[2]{file1.pdf} \includelastpages[4]{file2.pdf} \end{document}

The \settotalpagestomacro uses recent version of l3graphics to get number of pages (see this answer Get number of pages of external PDF).

The fitpaper option adjusts the paper size to the one of the inserted document.

The \includelastpages macro includes the last pages from a PDF file. The optional argument defines the number of pages (default value: 1).

Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283