davidgohel / flextable

table farming
https://ardata-fr.github.io/flextable-book/
562 stars 81 forks source link

Feature Request: Save as vector image format? #432

Closed N-Accumbens closed 2 years ago

N-Accumbens commented 2 years ago

Hello,

Great package, I'm just wondering if it'd be possible to save tables in a vector image format like svg? Having vector format images is great if you want to zoom-in to especially large tables.

davidgohel commented 2 years ago

Hello

Not exactly possible right now with a single command. There is one workaround via save_as_image:

library(flextable)
library(webshot2)

ft <- flextable(head(iris)) |> autofit()
save_as_image(x = ft, path = "ft.pdf", webshot = "webshot2")

The result is a vector image PDF.

davidgohel commented 2 years ago

It's now implemented thanks to grid graphics! (note it can be slow with large tables)

library(flextable)

ft <- flextable(iris) |> autofit()
gr <- gen_grob(ft, scaling = "fixed", fit = "fixed", just = "center")
dims <- dim(gr)
svglite::svglite(filename = "hello-grid-graphics.svg", width = dims$width + .1, height = dims$height + .1)
plot(gr)
dev.off()
Capture d’écran 2022-09-06 à 17 41 43
github-actions[bot] commented 1 year ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.