Learn R Programming

flextable (version 0.7.2)

save_as_image: save a flextable as an image

Description

save a flextable as a png, pdf or jpeg image.

Image generated with package 'webshot' or package 'webshot2'. Package 'webshot2' should be prefered as 'webshot' can have issues with some properties (i.e. bold are not rendered for some users).

The image is coming from a screenshot of the 'HTML' output. save_as_image() is a tool to make life easier for users. Nevertheless, the features have some limitations that can't be solved with flextable because they are not related to flextable:

  • png does support transparency,

  • jpeg does not support transparency,

  • webshot2 does not allow transparent background,

  • webshot does allow transparent background.

Usage

save_as_image(x, path, zoom = 3, expand = 10, webshot = "webshot")

Arguments

x

a flextable object

path

image file to be created. It should end with .png, .pdf, or .jpeg.

zoom, expand

parameters used by webshot function.

webshot

webshot package as a scalar character, one of "webshot" or "webshot2".

See Also

Other flextable print function: as_raster(), df_printer(), flextable_to_rmd(), htmltools_value(), knit_print.flextable(), plot.flextable(), print.flextable(), save_as_docx(), save_as_html(), save_as_pptx()

Examples

Run this code
ft <- flextable( head( mtcars ) )
ft <- autofit(ft)
tf <- tempfile(fileext = ".png")
if (FALSE) {
if( require("webshot") ){
  save_as_image(x = ft, path = "myimage.png")
}
}

Run the code above in your browser using DataLab