Note that there are some explanatory texts on larger screens.

plurals
  1. POcopying openXML image from one document to another
    text
    copied!<p>We have conditional Footers that <code>INCLUDETEXT</code> based on the client:</p> <p><code>IF $CLIENT = "CLIENT1" "{INCLUDETEXT "CLIENT1HEADER.DOCX"}" ""</code></p> <p>Depending on our document, there could be a varying amount of <code>IF/ELSE</code>, and these all work correctly for merging the correct files in the correct place.</p> <p>However, some of these documents may have client specific images/branding, which also need to be copied across from the <code>INCLUDETEXT</code> file.</p> <p>Below is the method that is called to replace any <code>Picture</code> elements that exist in the <code>IEnumerable&lt;Run&gt;</code> that is copied from the Source document to the Target document.</p> <p>The image is copied fine, however it doesn't appear to update the RID in my <code>Picture</code> or add a record into the .XML.Rels files. (I even tried adding a <code>ForEach</code> to add to all the headers and footers, to see if this made any difference.</p> <pre><code> private void InsertImagesFromOldDocToNewDoc(WordprocessingDocument source, WordprocessingDocument target, IEnumerable&lt;Picture&gt; pics) { IEnumerable&lt;Picture&gt; imageElements = source.MainDocumentPart.Document.Descendants&lt;Run&gt;().Where(x =&gt; x.Descendants&lt;Picture&gt;().FirstOrDefault() != null).Select(x =&gt; x.Descendants&lt;Picture&gt;().FirstOrDefault()); foreach (Picture pic in pics) //the new pics { Picture oldPic = imageElements.Where(x =&gt; x.Equals(pic)).FirstOrDefault(); if (oldPic != null) { string imageId = ""; ImageData shape = oldPic.Descendants&lt;ImageData&gt;().FirstOrDefault(); ImagePart p = source.MainDocumentPart.GetPartById(shape.RelationshipId) as ImagePart; ImagePart newPart = target.MainDocumentPart.AddPart&lt;ImagePart&gt;(p); newPart.FeedData(p.GetStream()); shape.RelId = target.MainDocumentPart.GetIdOfPart(newPart); string relPart = target.MainDocumentPart.CreateRelationshipToPart(newPart); } } } </code></pre> <p>Has anyone come across this issue before?</p> <p>It appears the OpenXML SDK documentation is a 'little' sparse...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload