0

Need to apply theme from one word document (DOCX) to another via manipulating the XMLs.

The road I'm going through is -
word/themes folder contains at least one theme#.xml and could have the rels folder containg relationship files. I decided not to touch the rels folder and copy all theme#.xmls (as could be more than one) present in word/theme folder. This is working for me.

I have two concerns over it:
1. Do I need to add theme1.xml.rels file present in word\theme_rels as well? It contains mapping to one image in word\media folder. Do I need to add the image mapping too?
2. For few themes such as "Quotable", the theme1.xml contains one reference in 'a:fmtScheme' node to relationship id, probably for DrawingML and shapes.

for ex:

<a:blipFill rotWithShape="1">
<a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId1">

As the "rId1" here refers to styles.xml and maintained in word_rels\document.xml.rels, my concern is the word_rels\document.xml.rels mapping to styles.xml could not be rId1 in the document to which theme is getting applied (for instance this could be rId5 for styles.xml). So, Do I need to change this in theme1.xml while copying to work it properly.

Any help would be greatly appreciated.

unknown_boundaries
  • 1,482
  • 3
  • 25
  • 47

1 Answers1

1

If this XML appears in theme1.xml, 'rId1' is a key in theme1.xml.rels, not the document.xml.rels. The relationship ids (rId#) are unique within a 'source' XML document but are not unique within the overall package (.docx file).

Since this one is a <a:blip> element, the relationship will be to an image part, e.g. image1.jpg. I suspect this one is a large-ish quotation mark image that appears in front of a pull-out quote.

If you want it to show up properly, you'll want to make sure those relationships and their target parts are reconstructed in your target package. That would mean "yes", you would want to add the theme1.xml.rels file in the right place, as well as the image file it refers to.

scanny
  • 26,423
  • 5
  • 54
  • 80
  • Thanks for your reply. I got your point on themes relationship file and the image reference in it. I'm assuming the 'rId1' is reference to styles.xml and mapping is in word\_rels\document.xml.rels. Do you think my assumption is correct about relationship id is always for styles.xml? If it is the case then I would probably need to inspect the word\_rels\document.xml.rels (Destination) and rId for styles.xml and would replace it in theme#.xml as well as in theme1.xml.rels file? – unknown_boundaries Jul 16 '14 at 09:41
  • I'm sorry you have mentioned it in answer and I missed it completely. Thanks. – unknown_boundaries Jul 16 '14 at 10:54
  • Although when I add word\theme\_rels\theme1.xml.rels and the image reference the word docx got corrupted, I think some other things are to be added as well. One such thing I could found is type definition "" in [Content_Types].xml. I can ask this as separate question but do could you think of any reason for this not rendering properly. I mean do we need to add something in word/settings.xml or word/websettings.xml. Thanks. – unknown_boundaries Jul 16 '14 at 11:16
  • Yes, when an "rId" reference appears in a part, its mapping will *always* appear in the rels file for that part. So if `rId9` appears in document.xml, the relationship it references is in document.xml.rels. Likewise in this case for `rId1` appearing in theme1.xml. That relationship will be in theme1.xml.rels. – scanny Jul 16 '14 at 11:17
  • 1
    You will need to have the content type mapping in there so Word knows how to deal with the image file. There wouldn't be any others though. Definitely not in settings.xml. The partname (path) you mention is odd though. I would think it would be word\theme\\_rels\theme1.xml.rels. Maybe that's just showing up oddly because of how the comment editor interprets backslashes though. The most likely problem is perhaps not having your relationships and references all correct. That can get very tedious to get right and is worth double-checking. – scanny Jul 16 '14 at 11:21
  • Ok yep the path printed incorrectly, I should have rechecked that before posting. word\theme\_rels\theme1.xml.rels is correct one. The slight modification I did is in added content type as "image/jpeg" for and this seems to be working now. Thanks for all the help. – unknown_boundaries Jul 16 '14 at 11:41