Page 1 of 1

Copying parts from 1 document to multiple documents

PostPosted: Sun Nov 08, 2009 3:58 am
by jbeltran
Hi,

I have the requirement to copy a header from one document to a set of multiple documents. To do this, I created new HeaderParts and set their JaxbElements from the old HeaderPart's Hdr object. The header's text is getting copied over correctly, but the image that's on the header isn't getting copied over.

To copy the image, I added that image part from the old header to new header. Only one of the documents I create have the image set correctly. Is there something I'm doing wrong? Is it because I'm copying the same reference to each of the new headers?

What's the best way to go about this?

I've been able to copy images multiple documents to 1 document (i.e. many to one), but not the other way around (i.e. one to many).

Justin

Re: Copying parts from 1 document to multiple documents

PostPosted: Sun Nov 08, 2009 1:49 pm
by jason
To understand what is happening here, it would be helpful to see your code and the resulting docx.

Obvious thing to check: Is the relId in the header xml which points to the image correct?

In principle I think you can have a single part object pointed to via a rel from a number of different documents, and things should work provided the code doesn't need to ask the part which is its owning rel or package. ie saving should work. But what is expected to work or not work is undocumented.

Having multiple packages reusing a single image part is obviously more memory efficient than actually the image part, but worst case, cloning is what you'd do.