2 title: "CairoHacks: Bookmarks and Rasters"
3 author: "Don Armstrong"
8 %\VignetteIndexEntry{CairoHacks}
9 %\VignetteEngine{knitr::knitr}
10 \usepackage[utf8]{inputenc}
13 ```{r setup, include=FALSE}
14 knitr::opts_chunk$set(echo=TRUE)
19 CairoHacks allows you to create bookmarks in PDF documents. This
20 requires the use of pdftk to actually create the bookmarks at the end
23 Here is a simple example:
26 Cairo::CairoPDF(file="example.pdf",onefile=TRUE)
27 plot(y~x,data.frame(x=1:5,y=1:5))
28 bookmarks <- make.pdf.bookmark("First plot")
29 plot(y~x,data.frame(x=1:5,y=1:5))
30 bookmarks <- bookmarks + make.pdf.bookmark("Second plot")
32 write.pdf.bookmarks(file="example.pdf",bookmarks)
35 This will create two bookmarks in the file `example.pdf` named "First
36 plot" and "Second plot" which point to the first and second pages,
39 Bookmarks requires the use of the CairoPDF device so that the current
40 page number can be obtained using the onSave Cairo Hook. In the
41 future, if other devices allow reporting the current page number, they
46 CairoHacks also allows you to create raster images (bitmaps) which can
47 then be embedded into a PDF. This is very useful, because sometimes
48 you have a huge number (millions) of points which you would like to
49 plot on a single plot without making the resultant PDF megabytes in
52 ```{r echo=TRUE,fig.keep="last"}
55 start_rasterplot(width=1024)
57 data=data.frame(y=rnorm(1E5),x=rnorm(1E5)))
58 raster.image <- stop_rasterplot(plot=FALSE)
59 grid::grid.raster(raster.image)
62 produces a plot with 10 million points, but is only 1024 pixels wide
63 by 1024 pixels tall. (The width is 1024 by default, and the height is
64 automatically scaled on the basis of the underlying graphics device.)