12

Is it possible to display a pdf file in an Rmarkdown file? Say, for example, a previously saved image myimage.pdf

What I am aiming is a form of

\includegraphics[width=0.5]{myimage.pdf}
shafee
  • 15,566
  • 3
  • 19
  • 47
user2809432
  • 142
  • 1
  • 1
  • 8

3 Answers3

7

An update from the very end of 2017

It is possible to import a PDF image using knitr::include_graphics(), e.g.

```{r label, out.width = "85%", fig.cap = "caption"}
include_graphics("path-to-your-image.pdf") 
```
shafee
  • 15,566
  • 3
  • 19
  • 47
ikashnitsky
  • 2,941
  • 1
  • 25
  • 43
  • 4
    **knitr::include_graphics("path-to-your-image.pdf")** worked for me, but **include_graphics("path-to-your-image.pdf")** did not. Is it possible that you missed to add **knitr::** in your example? – user2809432 Feb 09 '18 at 17:58
  • 2
    Sure. I assume you load knit at the very beginning – ikashnitsky Feb 09 '18 at 18:05
  • Nice that this sorta works now, but the size control does nothing for me in knitr 1.20 – daknowles Aug 27 '18 at 21:11
2

You can insert this directly into your R Markdown. The alternate name will only be displayed if the image does not load.

![Alternate Name](file.pdf){width=500px}
mel
  • 95
  • 1
  • 6
0

For the record and as suggested in the comments, this works perfectly fine as long as you're knitting to pdf (this is a LaTex command that won't work if you try to knit to HTML or docx though):

\includegraphics[width = \textwidth]{myimage.pdf}

You can change the width with something like

\includegraphics[width = 0.5\textwidth]{myimage.pdf}
FZS
  • 243
  • 1
  • 8