1

When knitting to word_document2, when using knitr::include_graphics on a pdf shows "The picture can't be displayed." where the image should be. It does work for .png.

```{r pressure, fig.cap = "testing", echo=FALSE}
plot(pressure)
```

inline image working

```{r, include = FALSE}
png("pressure.png")
plot(pressure)
dev.off()
```

```{r, include = FALSE}
pdf("pressure.pdf")
plot(pressure)
dev.off()
```

```{r pressure-png, fig.cap = "testing png", echo = FALSE}
knitr::include_graphics("pressure.png")
```

png working

```{r pressure-pdf, fig.cap = "testing pdf", echo = FALSE}
knitr::include_graphics("pressure.pdf")
```

pdf not working

evanmuise
  • 11
  • 2
  • 1
    I don't think Word supports PDF images, but I don't use Word, so I could be wrong. – Yihui Xie May 07 '21 at 01:56
  • «I could be wrong» Indeed you are. You can prove that by going to Insert|Object>Object>Create from File, then selecting a PDF to insert. The first page of the PDF will be displayed. The issue for the OP is that he's trying to insert it the wrong way (it's not a picture, as such). – macropod May 07 '21 at 03:01
  • @YihuiXie is it the same for html files? – evanmuise May 07 '21 at 19:28
  • @macropod Thanks! Then it's up to Pandoc if it supports inserting PDF images that way. – Yihui Xie May 07 '21 at 21:10
  • 1
    @evanmuise It depends on your web browser. Some browsers support PDF images, but I suspect most browsers don't. – Yihui Xie May 07 '21 at 21:10
  • Related question: https://stackoverflow.com/questions/72108773/knitrinclude-graphics-runs-but-image-cannot-be-displayed?noredirect=1#comment127443747_72108773 – Tom May 05 '22 at 14:39

0 Answers0