0
  1. I am using the officer library so I can use R to create a Microsoft word document.
  2. I am trying to user the headers_replace_img_at_bkm() func to do put our company logo in the header.
  3. 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:

  1. 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
  2. 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?

Krich
  • 1
  • Hello, you should not add your bookmark inside a single paragraph but on a single chunk of text (empty will also work). That what the message says – David Gohel Jan 27 '23 at 11:50
  • David, thank you so much for replying! I am your biggest fan!! This library is insanely awesome! Could you tell me more by what you mean by a "chunk of text"? Do I just need to be make sure I don't have the first character (the new paragraph) highlihted when I make the bookmark? @DavidGohel – Krich Jan 27 '23 at 16:11

0 Answers0