0

I'm trying to include the first and last page of a PDF document in a new PDF document that I create via org-mode's Latex export engine. With this I have two issues:

  1. I would like to include the first and last page of the external PDF document scaled to their real size and not scaled down to fit the margins of the new PDF. However, I have not found much information about the :scale parameter in org-mode's manual. If I run:
#+ATTR_LATEX:  :scale 1.0

or

#+ATTR_LATEX:  :scale 100.0

the external PDF is not included at all.

  1. I would like to be able to choose which page of the external PDF to include. The default behavior when including a link to an external PDF as in:
[[/my/directory/my-external-document.pdf]]

is to include only the first page of the PDF linked. How could I include another page, such as the last one?

Thank you all!

Daniel
  • 99
  • 9

1 Answers1

0

I think you'll get somewhere faster if you can separate out the first and last pages of the external PDF file into their own PDF files.

On Linux, you can use pdfseparate (part of the poppler-utils package) to separate pages out of the external PDF file. Let's say the last page is page 42 (you can determine how many pages the PDF file file has with pdfinfo which is in the same package):

pdfseparate -l 1 external-file.pdf foo-first.pdf
pdfseparate -f 42 external-file.pdf foo-last.pdf

Then use links to the separate pages:


* Test

The first page of the external PDF file looks like this:

[[/my/directory/foo-first.pdf]]

* Another test

The last page, magnified by a factor of 1.2, of the external PDF file looks like this:

#+ATTR_LATEX: :scale 1.2
[[/my/directory/foo-last.pdf]]

If you look at the produced TeX file, you should see something like this:

\documentclass[11pt]{article}

...
...

\begin{document}

\tableofcontents

\section{Test}
\label{sec:org13d6711}

The first page of the external PDF file looks like this:

\begin{center}
\includegraphics[width=.9\linewidth]{/tmp/foo-first.pdf}
\end{center}


\section{Another test}
\label{sec:orgd2e453b}

The last page, magnified by a factor of 1.2, of the external PDF file looks like this:

\begin{center}
\includegraphics[scale=1.2]{/tmp/foo-last.pdf}
\end{center}
\end{document}

Other OSes should allow you to split pages out of a PDF file similarly, but you'll have to figure out what is available on them - I can't help with that.

NickD
  • 27,023
  • 3
  • 23
  • 42
  • Thank you for your answer! Everything should work indeed but I've discovered that I have a problem on Latex's end (or on `xelatex`, which is what I am using together with the `memoir` class), as I get `! Undefined control sequence. \Gin@ewidth ->1\@textwidth` precisely at the point where the external PDF is asked to be included. Now I have to figure out what is wrong with my Latex (or Xelatex) – Daniel Nov 02 '21 at 19:07
  • You might want to post your TeX file somewhere and add a link to your question. You might also post a question on the TeX SE site. – NickD Nov 02 '21 at 20:34
  • Shouldn't that be `\Gin@width` without the `e`? – NickD Nov 02 '21 at 21:15
  • I know, but no, it's `\Gin@ewidth`. Thank you very much for your answer anyhow! I've upvoted it as it solves my problem as it was posed. – Daniel Nov 03 '21 at 21:26
  • though, do you reckon it is impossible to include whole PDF documents rather than only their first page? – Daniel Nov 03 '21 at 21:35
  • I think you can include a whole PDF document into a PDF document produced by LaTex (see e.g. [this](https://www.sascha-frank.com/Faq/include_pdf.html)), but you cannot do it by adding links to your Org mode file. OTOH, assuming you are (only) interested in producing a PDF from you Org mode file (and not e.g. HTML), you can always add `\includepdf[pages=-]{external-pdf}` directly into your Org mode file, assuming I'm reading that page correctly. Untested, just in case it's not clear. – NickD Nov 03 '21 at 22:02