Beeing able to render flextable as images is requiring package webshot or webshot2 to be available.

Run the following command to install webshot2. This package should be used instead of webshot as the latest can have some issues with html rendering.


Read more about it here.

Run the following command to install webshot. You may have to install phantomjs first.


What will be the size?

You can print a table as an image. In some case, you may want to know the exact width and height of the table to be sure to set up the correct aspect ratio. The function flextable_dim() will provide these informations without the need to produce the image.

Results are in inches. You can reuse them as values for knitr chunk options fig.asp, fig.width and fig.height.


To get an image file from a flextable object, use function save_as_image.

As an R graphic

To get a plot from a flextable object, use function plot.


To add a flextable on a ggplot2 object, one can use flextable::as_raster and grid.raster or rasterGrob. See Examples for an example.

With ggplot

You can also add the flextable (with grid::rasterGrob() and ggplot2::annotation_custom()) in a ggplot object. You need first to use as_raster() function that will return a raster version of the flextable.


gg1 <- ggplot(iris, aes(Sepal.Length, Petal.Length, color = Species) ) + geom_point()

ft_raster <- iris %>% group_by(Species) %>% 
  summarise_all(median) %>% 
  flextable() %>% autofit() %>% add_header_lines("means per Species") %>% 

gg2 <- ggplot() + 
  theme_void() + 
  annotation_custom(rasterGrob(ft_raster), xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)

cowplot::plot_grid(gg1, gg2, nrow = 2, ncol = 1, rel_heights = c(4, 1) )