Page 1 of 1

Image height and width in tag causes java heap error

PostPosted: Wed Feb 05, 2014 2:26 am
by davidrlee
I'm getting an error when the xhtml img tag has height and width of the image.

I get this in docx4j2.8.1 and 3.0.0. After reading the comment on http://stackoverflow.com/questions/15659076/does-docx4j-convert-xhtml-to-docx-in-memory I strip out the image height and width and it works fine.

Code: Select all
org.docx4j.org.xhtmlrenderer.load INFO:: Loaded document in ~28ms
org.docx4j.org.xhtmlrenderer.load INFO:: TIME: parse stylesheets  114ms
org.docx4j.org.xhtmlrenderer.match INFO:: media = print
org.docx4j.org.xhtmlrenderer.match INFO:: Matcher created with 128 selectors
Exception in thread "http-bio-8443-exec-5" 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.docx.DocxRenderer.layout(DocxRenderer.java:214)
   at org.docx4j.convert.in.xhtml.XHTMLImporterImpl.convert(XHTMLImporterImpl.java:657)