HI,
I'm facing problems with OutOfMemoryError while converting docx to html.
I'm using Java application:
package test;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import org.docx4j.Docx4J;
import org.docx4j.Docx4jProperties;
import org.docx4j.convert.out.HTMLSettings;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
public class TestDocxConverter {
public static void main(String[] args) throws Exception{
String inputfilepath = "C:\\dokumenty testowe\\Portal Agenta - Instrukcja użytkownika_v 3.0pop.docx";
WordprocessingMLPackage wordMLPackage;
wordMLPackage = Docx4J.load(new java.io.File(inputfilepath));
HTMLSettings htmlSettings = Docx4J.createHTMLSettings();
htmlSettings.setImageDirPath("C:\\dokumenty testowe" + "\\media");
htmlSettings.setImageTargetUri("C:\\dokumenty testowe" + "\\media");
htmlSettings.setWmlPackage(wordMLPackage);
OutputStream os, os2;
//os = new FileOutputStream("C:\\test6.html");
os2 = new ByteArrayOutputStream();
Docx4jProperties.setProperty("docx4j.Convert.Out.HTML.OutputMethodXML", true);
Docx4jProperties.setProperty("docx", true);
String output="";
try {
try {
//Docx4J.toHTML(htmlSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
Docx4J.toHTML(htmlSettings, os2, Docx4J.FLAG_EXPORT_PREFER_XSL);
} catch (Docx4JException e) {
System.out.println(e.toString());
}
} catch (OutOfMemoryError E) {
System.out.println(E.toString());
}
output = ((ByteArrayOutputStream)os2).toString("UTF-8");
System.out.println("------------------------");
System.out.println("output:");
System.out.println(output);
}
}
As you can see I'm trying to convert docx to html. My test document is "Portal Agenta - Instrukcja użytkownika_v 3.0pop.docx". It size is about 5MB, it has 64 pages and about 110 images. When I run my converter after some time I get a OutOfMemoryError errors:
[main] ERROR org.docx4j.XmlUtils - java.lang.OutOfMemoryError: Java heap space
javax.xml.transform.TransformerException: java.lang.OutOfMemoryError: Java heap space
I run java with maximum size for memory on Win2003 Server and 32bit Java (1536MB). Is it possible that converter consumes such amount of memory to convert 5MB docx? How to reduce memory consumption?
Regards,
Lucas