RTF Examples for FiguresSource:
This example shows how to create and embed figures into an RTF file as below.
Below is an example with adjusted page orientation, figure height and width.
The package allow user to embed multiple figures into one RTF document. The supported format is listed as below.
## type rtf_code ## 1 emf \\emfblip ## 2 png \\pngblip ## 3 jpeg \\jpegblip
png file as an example, the workflow can be summarized as:
- Save figures into PNG format. (e.g. using
- Read PNG files into R as binary file using
- Add optional features using
- Set up page and figure options using
- Encode rtf using
r2rtf::rtf_encode(doc_type = "figure"). (Note: it is important to set
doc_type = "figure"as the default is
doc_type = "tableto handle tables).
- Write rtf to a file using
emfformat, one may use the R package
devEMFto create the figure.
# Define the path of figure filename <- c("fig/fig1.png", "fig/fig2.png", "fig/fig3.png") filename %>% rtf_read_figure() %>% # read PNG files from the file path rtf_title("title", "subtitle") %>% # add title or subtitle rtf_footnote("footnote") %>% # add footnote rtf_source("[datasource: mk0999]") %>% # add data source rtf_figure() %>% # default setting of page and figure rtf_encode(doc_type = "figure") %>% # encode rtf as figure write_rtf(file = "rtf/fig-simple.rtf") # write RTF to a file
Features of page and figure can be set up in
- Page orientation:
- Figure height and width:
The figure height and width can be set up for each figure in a vector. The code below provides an example for these features.
filename %>% rtf_read_figure() %>% # read PNG files from the file path rtf_page(orientation = "landscape") %>% # set page orientation rtf_title("title", "subtitle") %>% # add title or subtitle rtf_footnote("footnote") %>% # add footnote rtf_source("[datasource: mk0999]") %>% # add data source rtf_figure( fig_height = 3.5, # set figure height fig_width = c(6, 7, 8) # set figure width individually. ) %>% rtf_encode(doc_type = "figure") %>% # encode rtf as figure write_rtf(file = "rtf/fig-landscape.rtf") # write RTF to a file