Here is my code to inject altChunks
- Code: Select all
PartName partName = new PartName("/test.docx");
AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(partName);
afiPart.setBinaryData(new FileInputStream("C:\\Temp\\segment.docx"));
ContentType contentType = new ContentType(
"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml");
afiPart.setContentType(contentType); // docx
Relationship altChunkRel = mainPart.addTargetPart(afiPart);
CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();
ac.setId(altChunkRel.getId());
// Get Body content array of objects
aBodyContent = mainPart.getJaxbElement().getBody().getContent();
// Spin thru all content controls and locate this segment
for (int i = 0; i < aSdtTag.size(); i++) {
if (aSdtTag.get(i).equals("segment")) {
// Remove the content control and insert the altChunk in its place
aBodyContent.remove(aSdtIndex.get(i).intValue());
aBodyContent.add(aSdtIndex.get(i), ac);
}
}
If I open the word document after injecting the altChunks in Word it opens fine and everything works.
Here is my code to process altChunks
- Code: Select all
File fWord = new File("C:\\Temp\\word.docx");
WordprocessingMLPackage wordPackage = WordprocessingMLPackage.load(fWord);
WordprocessingMLPackage newPackage = ProcessAltChunk.process(wordPackage);
The process fails with the following errors:
[0DA0:000A-0CD4] 06/15/2012 02:57:04 PM HTTP JVM: com.plutext.merge.DocumentBuilder.i(Unknown Source)
[0DA0:000A-0CD4] 06/15/2012 02:57:04 PM HTTP JVM: com.plutext.merge.DocumentBuilder.a(Unknown Source)
[0DA0:000A-0CD4] 06/15/2012 02:57:04 PM HTTP JVM: com.plutext.merge.DocumentBuilder.a(Unknown Source)
[0DA0:000A-0CD4] 06/15/2012 02:57:04 PM HTTP JVM: com.plutext.merge.DocumentBuilder.a(Unknown Source)
[0DA0:000A-0CD4] 06/15/2012 02:57:04 PM HTTP JVM: com.plutext.merge.DocumentBuilder.buildOpenDocument(Unknown Source)
[0DA0:000A-0CD4] 06/15/2012 02:57:04 PM HTTP JVM: com.plutext.merge.altchunk.ProcessAltChunk.a(Unknown Source)
[0DA0:000A-0CD4] 06/15/2012 02:57:04 PM HTTP JVM: com.plutext.merge.altchunk.ProcessAltChunk.process(Unknown Source)