Page 1 of 1

Problem in saving replicated image

PostPosted: Wed Feb 10, 2010 8:58 pm
by claudioiac
Hi Jason,
I am using the docx4j-2-2-2 distribution and I encountered a problem trying to open, manipolate and saving again a docx file.
I have figured out the problem: this word file has an header with an image but somehow is not reconigned as the same image in all the pages. This means that in the docx I have different pointers to apparently different file images but at the end they converge to the same real file image.
During the saving process I receive an exception because it's trying to save the file image more than once.
I think it would be enough if your code would just skip in case of replication instead than throws an exception blocking the saving procedure.
I would be grateful to you if you could provide a distribution with just this bug fixed. I would do it personally but for licence issues I cannot used a library built on myself.
Thank you very much in advance.

This is the exception:

org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:319)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:130)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:93)
at esa.esoc.ops.hsc.reporting.core.Traverse.createReport(Traverse.java:147)
at esa.esoc.ops.hsc.reporting.core.DOC4JComponent.createReport(DOC4JComponent.java:58)
at TestReporting.main(TestReporting.java:91)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:319)
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:360)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:314)
... 5 more
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:319)
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:360)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:314)
... 7 more
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Failed to put binary part
at org.docx4j.openpackaging.io.SaveToZipFile.saveRawBinaryPart(SaveToZipFile.java:396)
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:342)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:314)
... 9 more
Caused by: java.util.zip.ZipException: duplicate entry: word/media/image5.jpeg
at java.util.zip.ZipOutputStream.putNextEntry(Unknown Source)
at org.docx4j.openpackaging.io.SaveToZipFile.saveRawBinaryPart(SaveToZipFile.java:375)
... 11 more

Re: Problem in saving replicated image

PostPosted: Wed Feb 10, 2010 10:35 pm
by jason
Hi Claudio

I'll make the change.

Is it sufficient for you to use a nightly-2010XXYY.jar, or do you need a real distribution docx4j-2-X-Y.jar?

cheers .. Jason

Re: Problem in saving replicated image

PostPosted: Thu Feb 11, 2010 12:47 am
by claudioiac
Hi Jason,
thanks for your fast reply!
I realized that the version in SVN already solve this problem but introduces new other issues and further I need a real distribution.
I would be grateful to you if you just update the docx4j-2-2-2.jar with this bug.
Thank you in advance.
Cheers

Claudio

Re: Problem in saving replicated image

PostPosted: Thu Feb 11, 2010 9:09 am
by jason
There is a branch for 2.3.0 which I'd prefer to release, rather than messing around with 2.2.2.

Could you please tell me what new issues are introduced in SVN head? They should be easy for me to fix (if indeed they are present in the 2.3.0 branch). Is it just that a few classes moved, for example Inline to org.docx4j.dml.wordprocessingDrawing.Inline?

Re: Problem in saving replicated image

PostPosted: Thu Feb 11, 2010 7:46 pm
by claudioiac
Hi Jason,
I have noticed the moving of Inline.java or that I have to handle new exceptions but this are a minor things. What I saw is instead that I cannot use anymore the following instructions in the image creation:
long widthLong = BinaryPartAbstractImage.twipToEMU(context.getWidth());
long heightLong = BinaryPartAbstractImage.twipToEMU(height);
Inline inline = imagePart.createImageInline(filenameHint, altText, id1, id2, widthLong, heightLong);

Re: Problem in saving replicated image

PostPosted: Thu Feb 11, 2010 7:46 pm
by claudioiac
Hi Jason,
I have noticed the moving of Inline.java or that I have to handle new exceptions but this are a minor things. What I saw is instead that I cannot use anymore the following instructions in the image creation:
long widthLong = BinaryPartAbstractImage.twipToEMU(context.getWidth());
long heightLong = BinaryPartAbstractImage.twipToEMU(height);
Inline inline = imagePart.createImageInline(filenameHint, altText, id1, id2, widthLong, heightLong);

Re: Problem in saving replicated image

PostPosted: Thu Feb 11, 2010 9:17 pm
by jason
org.docx4j.UnitsOfMeasurement contains twipToEMU.

If you want to specify width and height, BinaryPartAbstractImage contains:

Code: Select all
   /**
    * Create a <wp:inline> element suitable for this image, which can be
    * linked or embedded in w:p/w:r/w:drawing, specifying height and width.  Note
    * that you'd ordinarily use one of the methods which don't require
    * you to specify height (cy).
    *
    * @param filenameHint
    *            Any text, for example the original filename
    * @param altText
    *            Like HTML's alt text
    * @param id1
    *            An id unique in the document
    * @param id2
    *            Another id unique in the document None of these things seem to
    *            be exposed in Word 2007's user interface, but Word won't open
    * the document if any of the attributes these go in (except @ desc) aren't
    *            present!
    * @param cx    Image width in twip
    * @param cy    Image height in twip
    * @param link  true if this is to be linked not embedded
    * @throws Exception
    */
   public Inline createImageInline(String filenameHint, String altText,
         int id1, int id2, long cx, long cy, boolean link) throws Exception



Set link = false.

Re: Problem in saving replicated image

PostPosted: Fri Feb 12, 2010 3:44 am
by claudioiac
Dear Jason,
thanks for this code; please just let me know when you are able to provide the new release and I will try with that one.
Thanks in advance
Claudio

Re: Problem in saving replicated image

PostPosted: Fri Feb 12, 2010 11:09 am
by jason
I will aim to do it on Monday

Re: Problem in saving replicated image

PostPosted: Tue Feb 16, 2010 8:40 pm
by claudioiac
Dear Jason,
Did you have already delivered the new release?
I am looking forward to use it.
Thanks and cheers,

Claudio

Re: Problem in saving replicated image

PostPosted: Wed Feb 17, 2010 12:05 pm
by jason
Hi Claudio

You can now find 2.3.0 in http://dev.plutext.org/docx4j/

Let me know how you go.

If its ok, i'll make a formal release announcement.

In the meantime, you can see the release notes at http://dev.plutext.org/trac/docx4j/brow ... README.txt

cheers

Jason

Re: Problem in saving replicated image

PostPosted: Wed Feb 17, 2010 8:21 pm
by claudioiac
Hi Jason,
the new release works perfectly!
Thank you very much!

Cheers,
Claudio

Re: Problem in saving replicated image

PostPosted: Fri Feb 19, 2010 4:10 pm
by jason
Glad to hear it :) . Thanks for letting me know Claudio.