I have a rather large XHTML (1,23 MB - 21 images) which is producing "java.lang.OutOfMemoryError: Java heap space" error when trying to convert it to DOCX. Java code for converting XHTML > DOCX is taken from sample file ConvertInXHTMLDocument.java.
Here is the stack trace:
- Code: Select all
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75)
at java.awt.image.Raster.createPackedRaster(Raster.java:467)
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1032)
at java.awt.GraphicsConfiguration.createCompatibleImage(GraphicsConfiguration.java:149)
at java.awt.GraphicsConfiguration.createCompatibleImage(GraphicsConfiguration.java:178)
at org.docx4j.org.xhtmlrenderer.util.ImageUtil.createCompatibleBufferedImage(ImageUtil.java:117)
at org.docx4j.org.xhtmlrenderer.util.ImageUtil.convertToBufferedImage(ImageUtil.java:246)
at org.docx4j.org.xhtmlrenderer.util.ImageUtil$AbstractFastScaler.getScaledInstance(ImageUtil.java:301)
at org.docx4j.org.xhtmlrenderer.util.ImageUtil.getScaledInstance(ImageUtil.java:174)
at org.docx4j.org.xhtmlrenderer.util.ImageUtil.getScaledInstance(ImageUtil.java:204)
at org.docx4j.org.xhtmlrenderer.swing.AWTFSImage$NewAWTFSImage.scale(AWTFSImage.java:72)
at org.docx4j.org.xhtmlrenderer.docx.Docx4jReplacedElementFactory.createReplacedElement(Docx4jReplacedElementFactory.java:60)
at org.docx4j.org.xhtmlrenderer.render.BlockBox.calcDimensions(BlockBox.java:677)
at org.docx4j.org.xhtmlrenderer.render.BlockBox.calcDimensions(BlockBox.java:631)
at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:778)
at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:735)
at org.docx4j.org.xhtmlrenderer.layout.InlineBoxing.layoutInlineBlockContent(InlineBoxing.java:203)
at org.docx4j.org.xhtmlrenderer.layout.InlineBoxing.layoutContent(InlineBoxing.java:165)
at org.docx4j.org.xhtmlrenderer.render.BlockBox.layoutInlineChildren(BlockBox.java:964)
at org.docx4j.org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:943)
at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:818)
at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:735)
at org.docx4j.org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:61)
at org.docx4j.org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:947)
at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:818)
at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:735)
at org.docx4j.org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:61)
at org.docx4j.org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:947)
at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:818)
at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:735)
at org.docx4j.org.xhtmlrenderer.docx.DocxRenderer.layout(DocxRenderer.java:214)
at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.convert(XHTMLImporterImpl.java:657)
And I'm attaching my html with images. I have "-Xms512m -Xmx1024m" JVM options included when starting my web app with Jetty.
I don't know where is the problem but I've been debugging step by step through "xhtmlrenderer" and something caught my eye. In class Docx4jReplacedElementFactory.java, line 60 says: "fsImage.scale(cssWidth, cssHeight);" and variables cssWidth and cssHeight had some crazy high values like 9000x5000 (even though image is 400x300). Maybe it helps.
Thanks, T