Add image to word doc header without using reference docx #102
Replies: 2 comments 1 reply
-
Yes, it is possible. It is then necessary to associate a content with an image and text in the relevant headers and or footers. The result is to be used as a template.
Or simpler
Then you have to use IMPORTANT You will have to update the officer version with |
Beta Was this translation helpful? Give feedback.
-
Hey David, Just following up here since I figured out how to do what I wanted. It wasn't really an addition to the header of the document itself, sorry that was the wrong path to ask for guidance on. Instead, what I wanted to do was the add the image to the top of the page in regular paragraph format (albeit with margins of 0), and I finally landed on a way to do it. In my .Rmd I read in the image (using a GoogleDrive ID that's fed in via parameter) and define it as an external image
(As a quick note: for the life of me, I could not set the external_image width and height using inches. No matter what inputs I gave it, the image would appear in my google doc as with width 0.15in and height 0.04in. The height and width I've specified in centimeters above are obviously bigger than a standard page, but for whatever reason they produce an image that hugs the top and side margins.) Then in the very first addition to what will show up in the output, I add the image using fpar()
And then I immediately follow this with a block_section() call to assign the crazy 0-margins for the section containing the image
And then the rest of the document looks the same and uses the formatting from my template docx. I hope this might be a helpful addition to the knowledge base - I couldn't find someone else who had tried to do this on StackOverflow but it seems like it could be a useful trick (since adding something to the header washes out the image itself). If you have additional guidance on why the image dimensions just don't seem to materialize when using inches I'd be happy to explore it some more. For some additional context, I'm eventually rendering these using a (lightly edited) function from user MilesMcBain (gdoc_render), which can be found HERE |
Beta Was this translation helpful? Give feedback.
-
Hello!
Hoping this capability doesn't currently exist and I've missed it; I've only seen threads about including images in reference docs to add an image to a Word output header. My situation is that I'm using officedown to create 16 different documents that need to have 16 different headers images (for 16 different organizations that I'm creating reports for). Overall I've found the package to be incredibly useful since I can programmatically and conditionally change the tables and text and styling elements like colors to match the organization, and I'd love to take a similar tack here. The issue I'm running into now is that the only guidance I can find for adding a header image to the produced document is to include that image in the reference template, so it seems like I'd have to create 16 different reference templates with each header image, which would sort of defeat the point. Ideally, I'd like to have the images stored somewhere in the cloud (like in a where my teammate who makes them can upload them) so that I could just include some code in the Rmd that could pull them down as it loops through the production of each Word doc and sticks the image in the first page's header.
I understand this is kind of niche, I just don't know how much of a pain it'd be to develop this capacity, and I'm really grateful for any guidance you have if this is already possible.
Beta Was this translation helpful? Give feedback.
All reactions