I want to replace an image in the header/footer in a .docx document, with R and preferably using the officer package by david gohel.
I am using the body_replace_text_at_bkm
function. I have tried to use the the example code from (https://davidgohel.github.io/officer/reference/body_replace_text_at_bkm.html).
template <- system.file(package = "officer", "doc_examples/example.docx")
img.file <- file.path( R.home("doc"), "html", "logo.jpg" )
doc <- read_docx(path = template)
doc <- headers_replace_img_at_bkm(x = doc, bookmark = "bmk_header",
value = external_img(src = img.file, width = .53, height = .7))
doc <- footers_replace_img_at_bkm(x = doc, bookmark = "bmk_footer",
value = external_img(src = img.file, width = .53, height = .7))
print(doc, target = tempfile(fileext = ".docx"))
I expect the R logo in the header and the footer. But i get the text "a" in the header and "another" in the footer. The bookmarks are still present.
The word document looks like this: example.docx
Can you help me out? Sorry for my english and sorry in case my question is not clear. This is my first question I ask on stackoverflow.