- I am using the officer library so I can use R to create a Microsoft word document.
- I am trying to user the headers_replace_img_at_bkm() func to do put our company logo in the header.
- I need a bookmark in the header so I can use the above script but I can't figure out how to get a bookmark in the header.
What I tried:
- I have put a simple string in the header of template word document and then in microsoft word I have clicked the "Bookmark" button and called it "InsideHeader". I did the exact same thing for my title and called that bookmark "Title". enter image description here
- In R, I call in the template and then ran docx_bookmarks.
library(officer)
library(magrittr)
doc3<-read_docx(path="Blank_Template.docx")
doc3 %>%
docx_bookmarks()
It only returns the bookmark "Title".
Regardless, I still attempted
img.file <- file.path( "company_logo.png" )
headers_replace_img_at_bkm(x = doc3, bookmark = "InsideHeader",
value = external_img(src = img.file))
and then got the following error.
Error in docxpart_replace_img_at_bkm(node = header$get(), bookmark = bookmark, : could not find any bookmark InsideHeader located INSIDE a single paragraph
How do you create a paragraph in the header of a document? Any thoughts on how I can gain access to the bookmark in the title so I can do the following and have my companies logo in the header?