11

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} 
3
  • 1
    Yes, pdf_output supports raw latex, so you can do as you suggested. You'll need to put units on the width, though. Commented Jan 21, 2015 at 19:13
  • I was able to do as you said and include it in the pdf output, thanks. Is there a way to include it in the HTML output? Commented Jan 21, 2015 at 22:25
  • 1
    Not unless you convert it to png or jpeg first. Commented Jan 22, 2015 at 1:39

3 Answers 3

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") ``` 
Sign up to request clarification or add additional context in comments.

3 Comments

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?
Sure. I assume you load knit at the very beginning
Nice that this sorta works now, but the size control does nothing for me in knitr 1.20
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} 

Comments

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} 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.