0

I want to include an excerpt of a pdf-document in my Beamer-presentation. Furthermore, I want to highlight a part of this document, i.e. draw a red rectangle around it, maybe even have an arrow point towards it.

I only have the free version of Adobe Acrobat Reader, so I don't even know how to do this without LaTeX. Except, of course, I can take a screenshot of the excerpt and then edit it using PowerPoint:

Is there a nice way to do this in Beamer ?

enter image description here

1
  • 1
    You can use \includegraphics[page=..., crop=...]{<your pdf file>} to select page and fragment inside a tikz node and add marks as is explained in Drawing on an image in TikZ
    – Ignasi
    Apr 27 '19 at 12:28
2

A little while ago I wrote some code for annotating images that works equally well for annotating PDF files inside beamer. My macros define an AnnotatedImage environment where the coordinates are scaled so that the rectangular image fits inside a suitably scaled unit square, which makes it pretty easy to draw on the image. For example, you can produce the following "beamer slide"

enter image description here

using the essentially the code:

  \begin{AnnotatedImage}[width=0.8]{abacus.pdf}
    \draw[red, rounded corners, thick](0.2,0.85) rectangle(0.5,0.71);
    \draw[<-,red](0.2,0.78)--++(-0.1,0);
  \end{AnnotatedImage};

[This MWE will not compile as I used a random PDF file abacus.pdf on my computer and you won't have this...unfortunately, nice packages like mwe don't supply PDF files.] The optional argument to the environment allows you set the mage dimensions and inside the environment you can use arbitrary tikz commands. In addition, there is also a \annotate command. See Image with some overlaid text for more details.

For a multi-page PDF file this almost certainly won't work but it will work if you extract the pages that you want to annotate. The other option would be to be use pdfpages to extract only the pages that you need. If you need this let me know as it shouldn't be hard to modify my code to use pdfpages directly.

Here is the full code:

\documentclass{beamer}
\usepackage{tikz}
\usepackage{xparse}

\tikzset{% styling for the overlay
  annotatedImage/x/.initial = 0.7,% default overlay position
  annotatedImage/y/.initial = 0.7,
  annotatedImage/width/.initial = 1,% default image width
  annotatedImage/.unknown/.code = {% unknown keys are appended to style
    % to append to a style we need to expand everything first
    \edef\tikzappend{\noexpand\tikzset{annotatedImage/.append style =
                {\pgfkeyscurrentname=\pgfkeyscurrentvalue}}}
    \tikzappend
  },
  annotatedImage/.style = {% default overlay style
    draw=red, ultra thick, rounded corners, rectangle,
  }
}

\newsavebox\annotatedImageBox% need to calculate the width and height

% internal helper functions
\newcommand\AnnotatedImageVal[1]{\pgfkeysvalueof{/tikz/annotatedImage/#1}}
\newcommand\SetUpAnnotatedImage[2]{% set keys and dimensions to scale image
    \tikzset{annotatedImage/.cd, #1}%
    \sbox\annotatedImageBox{\includegraphics[width=\AnnotatedImageVal{width}\textwidth,
                                          keepaspectratio]{#2}}%
    \pgfmathsetmacro\annotatedHeight{\ht\annotatedImageBox/28.453}% convert from px to a tikz length
    \pgfmathsetmacro\annotatedWidth{\wd\annotatedImageBox/28.453}%
}

% usage: \annotatedImage[node options]{image}{text}
\NewDocumentCommand\annotatedImage{ O{} m m}{%
  \bgroup% start a group to keep tikz changes local
    \SetUpAnnotatedImage{#1}{#2}%
    \begin{tikzpicture}[xscale=\annotatedWidth, yscale=\annotatedHeight]%
        \node[inner sep=0, anchor=south west] (image) at (0,0) {\usebox{\annotatedImageBox}};
        \node[annotatedImage] at (\AnnotatedImageVal{x},\AnnotatedImageVal{y}) {#3};
    \end{tikzpicture}%y
  \egroup%
}

% usage: \annotate <insert favourite node commands>;
\newcommand\annotate[1][]{\node[annotatedImage,#1]}

% usage: \begin{AnnotatedImage][width(default 1)]{image} tikz commands....\end{AnnotatedImage}
\newenvironment{AnnotatedImage}[2][1]{%
  \SetUpAnnotatedImage{#1}{#2}%
  \tikzpicture[xscale=\annotatedWidth, yscale=\annotatedHeight]
    \node[inner sep=0, anchor=south west] at (0,0) {\usebox{\annotatedImageBox}};
}{\endtikzpicture}


\begin{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{PDF example}

  \begin{AnnotatedImage}[width=0.8]{abacus.pdf}
    \draw[red, rounded corners, thick](0.2,0.85) rectangle(0.5,0.71);
    \draw[<-,red](0.2,0.78)--++(-0.1,0);
  \end{AnnotatedImage};

\end{frame}

\end{document}
3
  • thank you so much, Andrew! ... here is a link to the pdf I want to include: researchgate.net/publication/… ... so. I want to include only the second page, and only points 3) to 5). I want to mark the first two lines, as well as the complete paragraph 5). ... I have just realized: In pdf24-Creator, when isolating a single page from a pdf, it becomes either a jpg or a png. ... does this render things a little easier?
    – Luk
    Apr 27 '19 at 13:42
  • My code works equally well with jpg, png, pdf, ... If you only want (part of) one page then I recommend extracting it and using the code above.
    – user30471
    Apr 27 '19 at 22:38
  • ok. Thx, again!
    – Luk
    Apr 28 '19 at 12:29

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.