library(officer)
srcfile <- file.path(R.home("doc"), "html", "logo.jpg")
floatimg <- floating_external_img(
src = srcfile, height = 1.06 / 2, width = 1.39 / 2,
pos_x = 0, pos_y = 0,
pos_h_from = "margin", pos_v_from = "margin"
)
text <- paste0(
" is a floating image in a ",
paste0(rep("very ", 30), collapse = ""),
" long text!"
)
# docx example ----
x <- read_docx()
fp_t <- fp_text(font.size = 20, color = "red")
an_fpar <- fpar(floatimg, ftext(text, fp_t))
x <- body_add_fpar(x, an_fpar)
print(x, target = tempfile(fileext = ".docx"))
# rtf example ----
rtf_doc <- rtf_doc()
rtf_doc <- rtf_add(rtf_doc, an_fpar)
print(rtf_doc, target = tempfile(fileext = ".rtf"))
Run the code above in your browser using DataLab