import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.OpcPackage;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import java.io.File;
public class Testclass {
public void readFromdoc(){
// JAXBContext context = org.docx4j.jaxb.Context.jc;
String inputfilepath = System.getProperty("user.dir") + "\\" + "mytest.docx";
System.out.println(inputfilepath);
// Load the docx
WordprocessingMLPackage wordMLPackage=null;
try {
wordMLPackage = (WordprocessingMLPackage)OpcPackage.load(new java.io.File(inputfilepath), "password");
} catch (Docx4JException e1) {
System.out.println("Unable to call load method from OpcPackage");
e1.printStackTrace();
System.exit(0);
}
// Save it
String outputfilepath = System.getProperty("user.dir") + "/OUT_OpenAndSaveRoundTripTest.docx";
try {
wordMLPackage.save(new File(outputfilepath));
} catch (Docx4JException e) {
System.out.println("Unable to output file");
e.printStackTrace();
System.exit(0);
}
}
}
Users browsing this forum: Bing [Bot], Google [Bot] and 38 guests