Images in Document Builder Not getting Reused.


I am combining the same document multiple times with different information in each but the same images. I noticed in Document Builder it is supposed to reuse images but it is not.

Looking on line 2190
 if (newContentPart != item.ImagePart)
This seems to always be true, but the item.Compare on 2192 compares them as the same image.

What is line 2190 suppose to be doing? Is it safe to remove it, becuase once I do the document opens fine and is a lot smaller with only the 1 Image referenced on all the pages. If I leave the other if statement I get an image for each page with a huge document.



EricWhiteDpe wrote Jul 19, 2015 at 4:38 AM

I need to do research on this. It may be a bit before I can get to this. I am immersed in producing vNext of the Open XML SDK.

tgr86 wrote Aug 5, 2015 at 7:44 AM


try replacing the if statement with the following:

if (newContentPart.GetType() != typeof(MainDocumentPart) && newContentPart.GetType() != typeof(HeaderPart) && newContentPart.GetType() != typeof(FooterPart) && newContentPart != item.ImagePart)
This solved the issue for me... but I have only tested on a couple of documents so far...