Page 1 of 1

Can not save while the header contain TIFF image

PostPosted: Tue Feb 21, 2012 4:25 pm
by ChrisLiu
Hi, I got below exceptions when saving the docx file.
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Couldn't load file from C:\temp\1.docx
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:180)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:172)
at com.cliu.test.Docx4j.main(Docx4j.java:16)
Caused by: java.io.FileNotFoundException: C:\temp\1.docx (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:177)
... 2 more

I designed a docx with headers, and each header contain a TIFF image(picture.tif). Then loaded the docx with docx4j, saved to docx file back with no processing, got the exception.
I reviewed the source code and find the problem in org.docx4j.openpackaging.contenttype.ContentTypeManager class:
if (!partName.toLowerCase().endsWith("." + ContentTypes.EXTENSION_TIFF)) {
partName = partName + "." + ContentTypes.EXTENSION_TIFF;
}
The "tif" and "tiff" suffix for TIFF image are all legal, but just support the "tiff". If I change the code to this, the issue will be ok:
if (!partName.toLowerCase().endsWith("." + ContentTypes.EXTENSION_TIFF) && !partName.toLowerCase().endsWith(".tif")) {
partName = partName + "." + ContentTypes.EXTENSION_TIFF;
}

My project need this change to support TIFF image, how could I submit or anybody can help me to submit the change?

Re: Can not save while the header contain TIFF image

PostPosted: Tue Feb 21, 2012 11:14 pm
by sureshbabubv
Hi,

The exception is not related to TIFF type, it is showing that the file that you have specified is not found.

Code: Select all
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Couldn't load file from C:\temp\1.docx
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:180)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:172)
at com.cliu.test.Docx4j.main(Docx4j.java:16)
Caused by: java.io.FileNotFoundException: C:\temp\1.docx (The system cannot find the file specified)


Please add the following code before u r saving the file

Code: Select all
String sFinalFilename = "C:\temp\1.docx";

         File objFile = new File(sFinalFilename);
         if(!objFile.exists())
         {
            objFile.createNewFile();
         }


I hope this may solve your problem.

Thanks & Regards,
B.V.Suresh Babu.

Re: Can not save while the header contain TIFF image

PostPosted: Wed Feb 22, 2012 4:22 pm
by ChrisLiu
sureshbabubv wrote:Hi,

The exception is not related to TIFF type, it is showing that the file that you have specified is not found.

Code: Select all
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Couldn't load file from C:\temp\1.docx
at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:180)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.load(WordprocessingMLPackage.java:172)
at com.cliu.test.Docx4j.main(Docx4j.java:16)
Caused by: java.io.FileNotFoundException: C:\temp\1.docx (The system cannot find the file specified)


Please add the following code before u r saving the file

Code: Select all
String sFinalFilename = "C:\temp\1.docx";

         File objFile = new File(sFinalFilename);
         if(!objFile.exists())
         {
            objFile.createNewFile();
         }


I hope this may solve your problem.

Thanks & Regards,
B.V.Suresh Babu.


Sorry, I attached wrong exception, the exception should be below:
3453 [main] ERROR org.docx4j.openpackaging.io.SaveToZipFile - Part word/media/image1.tif not found!
org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:378)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:164)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:105)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.save(WordprocessingMLPackage.java:219)
at com.cliu.test.Docx4j.main(Docx4j.java:17)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:378)
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:428)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:373)
... 4 more
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:378)
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:428)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:373)
... 6 more
Caused by: java.lang.NullPointerException
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:397)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:373)
... 8 more
Exception in thread "main" java.lang.RuntimeException: Load docx from:C:\temp\1.docx failed.
at com.cliu.test.Docx4j.main(Docx4j.java:19)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:378)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:164)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:105)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.save(WordprocessingMLPackage.java:219)
at com.cliu.test.Docx4j.main(Docx4j.java:17)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:378)
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:428)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:373)
... 4 more
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:378)
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:428)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:373)
... 6 more
Caused by: java.lang.NullPointerException
at org.docx4j.openpackaging.io.SaveToZipFile.savePart(SaveToZipFile.java:397)
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:373)
... 8 more

Re: Can not save while the header contain TIFF image

PostPosted: Wed Feb 22, 2012 4:25 pm
by ChrisLiu
I attached the docx file. Just load it, and save it.

Re: Can not save while the header contain TIFF image

PostPosted: Wed Feb 22, 2012 10:27 pm
by sureshbabubv
Hi,

Please try this code
Code: Select all
String fileName = "/path/to/file";

// before adding the file to imagepart find the mimetype of the image
File file = new File(fileName);
mimeType = mimeTypesMap.getContentType(file);



// assign the content type to the imagepart
                       BinaryPartAbstractImage imagePart = BinaryPartAbstractImage
               .createImagePart(wpPackage, imageBytes);
         Inline inline = imagePart.createImageInline(fileNameHint, altText,
               id1, id2, false);
      
         ContentType objcontentType = new ContentType(mimeType);
         imagePart.setContentType(objcontentType);


I hope this may resolve your issue

Thanks & Regards,
B.V.Suresh Babu.

Re: Can not save while the header contain TIFF image

PostPosted: Mon Feb 27, 2012 10:21 pm
by ChrisLiu
sureshbabubv wrote:Hi,

Please try this code
Code: Select all
String fileName = "/path/to/file";

// before adding the file to imagepart find the mimetype of the image
File file = new File(fileName);
mimeType = mimeTypesMap.getContentType(file);



// assign the content type to the imagepart
                       BinaryPartAbstractImage imagePart = BinaryPartAbstractImage
               .createImagePart(wpPackage, imageBytes);
         Inline inline = imagePart.createImageInline(fileNameHint, altText,
               id1, id2, false);
      
         ContentType objcontentType = new ContentType(mimeType);
         imagePart.setContentType(objcontentType);


I hope this may resolve your issue

Thanks & Regards,
B.V.Suresh Babu.


Thanks for your solution, but unfortunately it not proper.
I use the docx4j to process the docx files from the clients, so:
1. The tiff image has been embedded while I get it.
2. I can not assume there is tiff image is embedded.

I test the tiff image in the body part of a docx file, it does not work as well. First, the tiff image must be embedded into the docx, second, the tiff image must have the suffix ".tif" but not ".tiff".

Thanks,
Chris Liu

Re: Can not save while the header contain TIFF image

PostPosted: Mon Jun 11, 2012 10:37 pm
by tuomopo
Hi,

Any solution for this problem?
Seems to occur in versions 2.7.0 and 2.8.0.

Image seems to work only if it's in .tiff format but not for .tif format.
.tif format is correct format so it should work.

Should this be posted on error tickets and any ideas if this fix is coming on update 2.8.1?

Code: Select all
11.06.12 13:58:27.037 ERROR SaveToZipFile:368 - Part word/media/image1.tif not found!
org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships
at org.docx4j.openpackaging.io.SaveToZipFile.addPartsFromRelationships(SaveToZipFile.java:378)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:164)
at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:105)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.save(WordprocessingMLPackage.java:219)


thanks,
Tuomo

Re: Can not save while the header contain TIFF image

PostPosted: Thu Jun 21, 2012 10:51 pm
by jason
Created https://github.com/plutext/docx4j/issues/11 and scheduled for 2.8.1.

Re: Can not save while the header contain TIFF image

PostPosted: Sun Sep 02, 2012 9:19 am
by jason

Re: Can not save while the header contain TIFF image

PostPosted: Mon Sep 03, 2012 1:15 pm
by jason

Re: Can not save while the header contain TIFF image

PostPosted: Mon Apr 07, 2014 1:26 pm
by Radagast
hey Jason.

Any idea if we miss .wmf image format too? No idea about the context other than those are formula images of any of our chair's lecturers. Any help appreciated.
Code: Select all
16983 DEBUG o.d.o.i.Save              - For Relationship Id=rId18__1127224101 Source is /, Target is word/media/image6__1.wmf
16983 DEBUG o.d.o.i.Save              - Getting part /word/media/image6__1.wmf
16983 DEBUG o.d.o.i.Save              - org.docx4j.openpackaging.parts.WordprocessingML.MetafileWmfPart
16983 DEBUG o.d.o.i.Save              - .. saving binary stuff
16983 DEBUG o.d.o.i.s.ZipPartStore    - /word/media/image6__1.wmf is clean
org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships of /
   at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:390)
   at org.docx4j.openpackaging.io3.Save.save(Save.java:192)
   at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:442)


Btw. the part name is renamed, otherwise it saves fine (or it is because there were no relationships in the mainDocument's relationshipsPart. That could be the reason why it saved fine prior to renaming and adding too.).
Code: Select all
new_rel = /*target_rp*/wmlPackage.getMainDocumentPart()
                                 .addTargetPart(source_part_to_rel, AddPartBehaviour.RENAME_IF_NAME_EXISTS, /*wmlPackage.getContentTypeManager(),*/ source_rel.getId());
//HERE A SHORTCUT IS EVENTUALLY SET THE REST IS EQUAL TO ABOVE         

Re: Can not save while the header contain TIFF image

PostPosted: Mon Apr 07, 2014 4:49 pm
by jason
There should be a nested exception after "Failed to add parts from relationships of /". If so, could you post it?

Re: Can not save while the header contain TIFF image

PostPosted: Mon Apr 07, 2014 5:21 pm
by Radagast
Okay, you're right, there is WMF support there. My bad.

Here is the complete error stacktrace. strangely for another image, that was not renamed it worked fine:
Code: Select all
15118 DEBUG o.d.o.i.Save              - .. saving binary stuff
15118 DEBUG o.d.o.i.s.ZipPartStore    - /word/media/image4.wmf is clean
15119 INFO  o.d.o.i.s.ZipPartStore    - success writing part: word/media/image4.wmf
15119 DEBUG o.d.o.i.Save              - For Relationship Id=rId22 Source is /word/document.xml, Target is embeddings/oleObject8.bin
15119 DEBUG o.d.o.i.Save              - Getting part /word/embeddings/oleObject8.bin
15119 DEBUG o.d.o.i.Save              - org.docx4j.openpackaging.parts.WordprocessingML.OleObjectBinaryPart
15119 DEBUG o.d.o.i.Save              - .. saving binary stuff
15119 DEBUG o.d.o.i.s.ZipPartStore    - /word/embeddings/oleObject8.bin is clean
15120 INFO  o.d.o.i.s.ZipPartStore    - success writing part: word/embeddings/oleObject8.bin
15126 DEBUG o.d.o.i.Save              - For Relationship Id=rId18__811960591 Source is /word/document.xml, Target is media/image6__1.wmf
15126 DEBUG o.d.o.i.Save              - Getting part /word/media/image6__1.wmf
15127 DEBUG o.d.o.i.Save              - org.docx4j.openpackaging.parts.WordprocessingML.MetafileWmfPart
15127 DEBUG o.d.o.i.Save              - .. saving binary stuff
15127 DEBUG o.d.o.i.s.ZipPartStore    - /word/media/image6__1.wmf is clean
org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships of /
   at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:390)
   at org.docx4j.openpackaging.io3.Save.save(Save.java:192)
   at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:442)
   at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:407)
   at aufgaben_db.Global.mergeSourceFileIntoTargetFile(Global.java:3626)
   at aufgaben_db.Global.mergeSourceFileIntoTargetFile(Global.java:3210)
   at aufgaben_db.Global.joinToFile(Global.java:2635)
   at aufgaben_db.Global.joinToFile(Global.java:2497)
   at org.apache.jsp.action_draft_005fto_005fsheet_jsp._jspService(action_draft_005fto_005fsheet_jsp.java:241)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
   at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
   at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
   at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
   at org.apache.jsp.action_inc_jsp._jspService(action_inc_jsp.java:329)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
   at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
   at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
   at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
   at org.apache.jsp.index_jsp._jspService(index_jsp.java:213)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
   at java.lang.Thread.run(Thread.java:722)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Failed to add parts from relationships of /word/document.xml
   at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:390)
   at org.docx4j.openpackaging.io3.Save.savePart(Save.java:442)
   at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:385)
   ... 52 more
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Failed to put binary part
   at org.docx4j.openpackaging.io3.stores.ZipPartStore.saveBinaryPart(ZipPartStore.java:398)
   at org.docx4j.openpackaging.io3.Save.savePart(Save.java:418)
   at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:385)
   ... 54 more
Caused by: java.io.IOException: part '/word/media/image6__1.wmf' not found
   at org.docx4j.openpackaging.io3.stores.ZipPartStore.saveBinaryPart(ZipPartStore.java:361)
   ... 56 more
Apr 07, 2014 8:06:24 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.io.IOException: part '/word/media/image6__1.wmf' not found
   at org.docx4j.openpackaging.io3.stores.ZipPartStore.saveBinaryPart(ZipPartStore.java:361)
   at org.docx4j.openpackaging.io3.Save.savePart(Save.java:418)
   at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:385)
   at org.docx4j.openpackaging.io3.Save.savePart(Save.java:442)
   at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:385)
   at org.docx4j.openpackaging.io3.Save.save(Save.java:192)
   at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:442)
   at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:407)
   at aufgaben_db.Global.mergeSourceFileIntoTargetFile(Global.java:3626)
   at aufgaben_db.Global.mergeSourceFileIntoTargetFile(Global.java:3210)
   at aufgaben_db.Global.joinToFile(Global.java:2635)
   at aufgaben_db.Global.joinToFile(Global.java:2497)
   at org.apache.jsp.action_draft_005fto_005fsheet_jsp._jspService(action_draft_005fto_005fsheet_jsp.java:241)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
   at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
   at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
   at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
   at org.apache.jsp.action_inc_jsp._jspService(action_inc_jsp.java:329)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
   at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
   at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
   at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
   at org.apache.jsp.index_jsp._jspService(index_jsp.java:213)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
   at java.lang.Thread.run(Thread.java:722)

Apr 07, 2014 8:06:24 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.io.IOException: part '/word/media/image6__1.wmf' not found
   at org.docx4j.openpackaging.io3.stores.ZipPartStore.saveBinaryPart(ZipPartStore.java:361)
   at org.docx4j.openpackaging.io3.Save.savePart(Save.java:418)
   at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:385)
   at org.docx4j.openpackaging.io3.Save.savePart(Save.java:442)
   at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:385)
   at org.docx4j.openpackaging.io3.Save.save(Save.java:192)
   at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:442)
   at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:407)
   at aufgaben_db.Global.mergeSourceFileIntoTargetFile(Global.java:3626)
   at aufgaben_db.Global.mergeSourceFileIntoTargetFile(Global.java:3210)
   at aufgaben_db.Global.joinToFile(Global.java:2635)
   at aufgaben_db.Global.joinToFile(Global.java:2497)
   at org.apache.jsp.action_draft_005fto_005fsheet_jsp._jspService(action_draft_005fto_005fsheet_jsp.java:241)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
   at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
   at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
   at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
   at org.apache.jsp.action_inc_jsp._jspService(action_inc_jsp.java:329)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
   at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
   at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
   at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
   at org.apache.jsp.index_jsp._jspService(index_jsp.java:213)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
   at java.lang.Thread.run(Thread.java:722)

Apr 07, 2014 8:06:24 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.io.IOException: part '/word/media/image6__1.wmf' not found
   at org.docx4j.openpackaging.io3.stores.ZipPartStore.saveBinaryPart(ZipPartStore.java:361)
   at org.docx4j.openpackaging.io3.Save.savePart(Save.java:418)
   at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:385)
   at org.docx4j.openpackaging.io3.Save.savePart(Save.java:442)
   at org.docx4j.openpackaging.io3.Save.addPartsFromRelationships(Save.java:385)
   at org.docx4j.openpackaging.io3.Save.save(Save.java:192)
   at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:442)
   at org.docx4j.openpackaging.packages.OpcPackage.save(OpcPackage.java:407)
   at aufgaben_db.Global.mergeSourceFileIntoTargetFile(Global.java:3626)
   at aufgaben_db.Global.mergeSourceFileIntoTargetFile(Global.java:3210)
   at aufgaben_db.Global.joinToFile(Global.java:2635)
   at aufgaben_db.Global.joinToFile(Global.java:2497)
   at org.apache.jsp.action_draft_005fto_005fsheet_jsp._jspService(action_draft_005fto_005fsheet_jsp.java:241)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
   at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
   at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
   at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
   at org.apache.jsp.action_inc_jsp._jspService(action_inc_jsp.java:329)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
   at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
   at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
   at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
   at org.apache.jsp.index_jsp._jspService(index_jsp.java:213)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
   at java.lang.Thread.run(Thread.java:722)


Surely I missed something, here's more code:
Code: Select all
... up to come, eclipse just crashed

Re: Can not save while the header contain TIFF image

PostPosted: Mon Apr 07, 2014 5:34 pm
by Radagast
(hope this is fine, simply remove if this is post is only clutter)
Code: Select all
                                        RelationshipsPart target_rp = target_allRelationshipsParts.get(allRelationshipsParts_index);
               RelationshipsPart source_rp = source_allRelationshipsParts.get(allRelationshipsParts_index);
               
               for (Relationship source_rel : source_rp.getRelationships().getRelationship() ) {
                  
                  Part source_part_to_rel = source_rp.getPart(source_rel);
                  if (source_part_to_rel == null) {
                     if (target_rp.getPart(source_rel.getTarget()) == null) {
                        // => this target does not exist anywhere.
                        continue;
                     }
                     // is it one of those relationships where we reuse the existing? Because then we continue so that the source content that might use it, can use it. If we skipped instead, then the relationship might not get into target. But it should. Though it is strange that there was no corresponding target part then. Perhaps it should really be skipped. Or this is an auto-repair functionality?
                     else if (!source_rel.getType().equals(Namespaces.IMAGE)) {//TODO put into a list to not have to update at more than one place.
                        source_part_to_rel = target_rp.getPart(source_rel.getTarget());
                     }
                     //else skip as IMAGES would be copied and we wish to avoid redundant content (in this case double images).
                  }
                  
                  String source_rel_rId_old = source_rel.getId();
                  setUniqueRelId(source_rel, wmlPackage /*where it should be unique*/);
                  
                  // we take over images and rename those if they already exist in the target  (TODO only if content equal, resue existing):
                  Relationship new_rel = null; //<-- instead of that we could insert source rel prior to adding the Part. then the existing would be reused but the content types are not updated and perhaps other dangerous things.
                  if (source_rel.getType().equals(Namespaces.IMAGE)) {
                     
                     source_part_to_rel.setPackage(source_wMLPac);//<-- very important! for operating on the correct package when adding/removing the part.
                     // Does the part name already exist in the target package?
                     if (wmlPackage.getParts().getParts().get(source_part_to_rel.getPartName()) != null) {
                        /* as we wish to add this part without overwriting one with the same pathTo, i.e.partName,
                           we check if the partName is given already (as this is the Map's key, so it's unique.)
                           => change if required. update all references (relationships).
                        */
                        int loopCountLimit = 100;
                        int number = 0;
                        String[] str_parts = source_part_to_rel.getPartName().getName().split("[.]");
                        String partName_old_base = str_parts[0];
                        PartName partName_old = source_part_to_rel.getPartName();
                        PartName partName_new = partName_old; //start with the old one.
                        while (++number < loopCountLimit
                              //&& wmlPackage.getParts().getParts().containsKey(source_part_to_rel.getPartName())) {
                              && wmlPackage.getParts().getParts().get(partName_new) != null) {
                           
                           String partName_new_str;
                           partName_new_str = partName_old_base + "__" + number;
                           String pointAfterFirstRound = "";
                           for (String str_part : str_parts) {
                              // skip the first entry as this is treated above already.
                              if (!pointAfterFirstRound.isEmpty()) {
                                 partName_new_str += pointAfterFirstRound + str_part;
                              }
                              pointAfterFirstRound = ".";
                           }
                           partName_new = new PartName(partName_new_str);
                        }
                        // still no unique name? => repeat with random number
                        number = 0;
                        while (++number < loopCountLimit
                              //&& wmlPackage.getParts().getParts().containsKey(source_part.getPartName())) {
                              && wmlPackage.getParts().getParts().get(partName_new) != null) {
                           
                           String partName_new_str;
                           partName_new_str = partName_old_base + "__" + ((long)(Math.random() * 1000000));
                           String pointAfterFirstRound = "";
                           for (String str_part : str_parts) {
                              // skip the first entry as this is treated above already.
                              if (!pointAfterFirstRound.isEmpty()) {
                                 partName_new_str += pointAfterFirstRound + str_part;
                              }
                              pointAfterFirstRound = ".";
                           }
                           partName_new = new PartName(partName_new_str);
                        }
                        
                        // now we hopefully have a unique partname. => rename the part:
                        source_part_to_rel.setPartName(partName_new);
                        
                     }
                     //else the source part name is already unique in the target package. No rename required.
                     
                     // Add the source part:
                            // takes care of part name uniqueness renaming already.
                     new_rel = /*target_rp*/wmlPackage.getMainDocumentPart().addTargetPart(source_part_to_rel, AddPartBehaviour.RENAME_IF_NAME_EXISTS, /*wmlPackage.getContentTypeManager(),*/ source_rel.getId());
                     
                  }
                  // for others we prefer reusing existing doubles:
                  else {//if (source_rel.getType().equals(Namespaces.STYLES)) {
                     // takes care of part name uniqueness renaming already:
                     new_rel = /*target_rp*/wmlPackage.getMainDocumentPart().addTargetPart(source_part_to_rel, AddPartBehaviour.REUSE_EXISTING, /*wmlPackage.getContentTypeManager(),*/ source_rel.getId());
                     // now as the part could have been reused, fetch the part:
                     Part old_source_part_to_rel = source_part_to_rel;
                     source_part_to_rel = wmlPackage.getMainDocumentPart().getRelationshipsPart().getPart(new_rel);
                  }
                  

                  source_part_to_rel.setPackage(wmlPackage); //<-- always the target. not the source one.
                  // otherwise this things happen already in addPart which calls loadPart (only if not REUSING EXISTING).
                  // new relationship was already inserted into the relationshipPart.
                  //target_rp.addRelationship(new_rel); new_rel.setParent(target_rp);

                     
               }
         
            }

Re: Can not save while the header contain TIFF image

PostPosted: Mon Apr 07, 2014 5:55 pm
by Radagast
To reproduce simply try to merge the attached docx (above) with itself.

All images collide. Thus it's renaming the part. => Strangely this renders the part resource unfindable. So probably I have to rename this resource too. But how could this be done, renaming the part URI?

There is ZIP-handling involved for renaming but I don't know if the rename actions are queued, so that the docx4j package save-function can take care of this.

Or is the resource renamed automatically if the partName changed? And the partNameURI is synchronised too? I couldn't find any code it does. So surely I have to take of it. Do you have any tip on how to best rename the underlying resource i.e. in this case the image
Code: Select all
/word/media/image6.wmf   -->   /word/media/image6__1.wmf
?

Otherwise I can't explain why it can't find the image anymore after renaming.

Re: Can not save while the header contain TIFF image

PostPosted: Mon Apr 07, 2014 7:17 pm
by Radagast
To share my research so far:
Probable causes:
  1. [strike]Trying to rename the same part twice (as more than one relationship might point to the same target).[/strike] <- tested by elimination => not the root cause
  2. partByteArrays in ZipPartStore.save(buffer) is null because he part originates from another wml package:
    Code: Select all
                  } else if (this.sourcePartStore==this) {

                     // Just use the ByteArray
                     log.debug(part.getPartName() + " is clean" );
                      ByteArray byteArray = partByteArrays.get(
                            part.getPartName().getName().substring(1) );
                      if (byteArray == null) throw new IOException("part '" + part.getPartName() + "' not found");
                      bytes = byteArray.getBytes();

                  }
  3. more?

To mitigate case 2 could we make a remove and then readd with correct String key. i.e.
Code: Select all
partByteArrays.put(partName, part.getBytes())
in setPartName()?

Somehow the zipEntries must be kept up to date after a rename. Or am I missing something. Probably you are already doing this. Will do more research ...

Re: Can not save while the header contain TIFF image

PostPosted: Mon Apr 07, 2014 7:36 pm
by jason
Taking a step back for a moment, what are you trying to achieve?

Re: Can not save while the header contain TIFF image

PostPosted: Mon Apr 07, 2014 7:55 pm
by Radagast
Merging 2 docx. Renaming images with part name that exists in target package.


more research @case 2:
Has to be called on the correct TargetPartStore.
Code: Select all
        if (part instanceof BinaryPart ) {
         log.debug(".. saving binary stuff" );
         p.getTargetPartStore().saveBinaryPart( part );
         
      }


So we could add Part.bytes to the PartStore.partByteArrays probably best in Part.loadPart() but I'm not sure:
Code: Select all
target_wmlPackage.getTargetPartStore()


Or we change the ZipPartStore.partByteArrays type from Map<String, ByteArray> to Map<PartName, ByteArray> as this could ensure that on a partName rename the key is updated too. Currently the String partName is simply overriden on rename. This results in the reference being lost and the ZipPartStore.partByteArrays key not being updated.

Hope I'm wrong.
Still this type change seems to be the cleanest solution to me. But also difficult as the PartName then already has to be known when loading the Part from the wmlPackage ZipFile.

As a workaround I wanted to update the key manually but I can't access the property as it's protected I guess.
Code: Select all
if (source_wMLPac.getTargetPartStore() instanceof ZipPartStore) {
   if (!((ZipPartStore) source_wMLPac.getTargetPartStore()).partExists(partName_new.getName())) {
      if (((ZipPartStore) source_wMLPac.getTargetPartStore()).partExists(partName_old.getName())) {
         // then the old at least exists. Copy it over.
         ((ZipPartStore) source_wMLPac.getTargetPartStore()).partByteArray.put(
               partName_new.getName()
               ,
               ((ZipPartStore) source_wMLPac.getTargetPartStore()).partByteArray.get(partName_old.getName())
               
           );
      }
   }
}

I keep the old key pointing to the same binary data for safety reasons. Should not be necessary for consistency.

Source wml package is used because I perform the renaming of the part there instead within the addPart() where this also is done. (one of my desperate efforts to fix this error , so far I'm fruitless :/)

Re: Can not save while the header contain TIFF image

PostPosted: Mon Apr 07, 2014 8:59 pm
by Radagast
Another research update:
As my system is low on memory, the VM could have unloaded the binary cache. See Jason's note:
Code: Select all
   /**
    * Store buffer thru soft reference so it could be
    * unloaded by the java vm if free memory is low.
    */
   private Reference<ByteBuffer> bbRef = null;
   
   /**
    * @since 3.0
    */
   public boolean isLoaded() {
      
      if (this.bb != null) {
         return true;
      }
      
      return (this.bbRef != null);
   }


Then this results in the else clause being executed and there the part can't be found in the partByteArrays map:
Code: Select all
if (((BinaryPart)part).isLoaded() ) {

    bytes = ((BinaryPart)part).getBytes();

} else if (this.sourcePartStore==this) {

     // Just use the ByteArray
     log.debug(part.getPartName() + " is clean" );
     ByteArray byteArray = partByteArrays.get(
             part.getPartName().getName().substring(1) );
    if (byteArray == null) throw new IOException("part '" + part.getPartName() + "' not found");
    zos.write( byteArray.getBytes() );

}


We could try setting the sourcePartStore to the source_wmlPackage.getTargetPartStore() where the part originates from, but this can only be set for a package as a whole and not fine grained for each part.

And there the same issue might occur as the part has been renamed in the meantime; rendering the partByteArrays value unreachable there too as the partName changed (and this is the key for the partByteArrays binary entry we are interested in).

Re: Can not save while the header contain TIFF image

PostPosted: Mon Apr 07, 2014 11:01 pm
by jason
I don't know whether you've seen my old blog post from 2010:-

http://www.docx4java.org/blog/2010/11/m ... documents/

but in the general case, merging docx files without loss of formatting is quite complex.

That's why my company offers a commercial solution to do it, included in the Docx4j Enterprise Edition.

If you want or need a fully ASL licensed solution, you are welcome to build your own merging capability.

But as I'm sure you'll appreciate, the time I have available to answer questions on this forum is necessarily limited. And its difficult to justify using that time to help you to duplicate what we already provide!

I guess the fact that the Enterprise Edition exists should reassure you it is entirely possible to do what you are seeking based on docx4j as it stands (the Enterprise Edition doesn't change or replace any of docx4j, it just adds additional functionality). Over 3 years in use with a number of customers, the MergeDocx component has been progressively refined and addresses all the use cases these customers have directed at it.

Having said all that, in general, parts belong to a single package, and if you intend to save that package again, you need to leave the hierarchy intact. The hierarchy is expressed through the relationship elements. In advanced usages, you can reattach parts to a different package, or copy them, but you'll always need to ensure update the rels appropriately and rename parts as necessary to ensure uniqueness. Hope that helps a bit...

Re: Can not save while the header contain TIFF image

PostPosted: Tue Apr 08, 2014 4:34 am
by Radagast
I have expected this answer and fully tolerate it. I even decided to donate.

That's why I was careful with posting more code. I take care of copying and maintaining all that is needed.
There is even a hacky solution to fix my problem without changing the library. Still I just wondered if this shouldn't be fixed in the main library.
But I see your point, there must be something you live from and I will not let you down.

Thank you so much for all your help so far. (e.g. with the OutOfProperties Error which I figured is a hot-code-reloading issue).

Really awesome library. Glad you guys and gals put it together.

Re: Can not save while the header contain TIFF image

PostPosted: Tue Apr 08, 2014 6:04 am
by Radagast
Wish to edit the first line, sounds not very nice: Should be: 'Have expected this answer as I was not specific enough. I fully tolerate it though.'

Is there a possibility to donate? I'm a firm believer in crowd-funding. ;) Myself I'm always critizised already for developing even costly (in comparison to software) hardware. Still I believe 'true' Open source is helping this world become a better place. (and your open source library is already a huge contribution, so don't feel bad, feel good. there is no reason to worry about me, I'm not important. I will find a way.)

Keep up the cool work (and interesting that there is no edit function though I also think it's not really necessary, we can live without.).

Also sorry for posting in this topic as the error at first looked similar to the one shown here with the TIFF image getting a false image added by docx (what you already fixed - quick as always).