org.docx4j.samples.AltChunkXHTMLRoundTrip Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of docx4j-ImportXHTML-samples Show documentation
Show all versions of docx4j-ImportXHTML-samples Show documentation
docx4j-ImportXHTML converts XHTML to OpenXML WordML (docx) using docx4j
The newest version!
package org.docx4j.samples;
import org.docx4j.XmlUtils;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.AltChunkType;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
/**
* Create a docx containing an XHTML AltChunk,
* and then convert that to normal docx content.
* @author jharrop
*
*/
public class AltChunkXHTMLRoundTrip {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
mdp.addParagraphOfText("Paragraph 1");
// Add the XHTML altChunk
String xhtml = "Import me Hello World!
";
mdp.addAltChunk(AltChunkType.Xhtml, xhtml.getBytes());
mdp.addParagraphOfText("Paragraph 3");
// Round trip
mdp.convertAltChunks();
// Display result
System.out.println(
XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true));
wordMLPackage.save(new java.io.File(System.getProperty("user.dir") + "/OUT_AltChunkXHTMLRoundTrip.docx"));
}
}