Details
-
Type: Bug
-
Status: Closed
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: 4.2
-
Fix Version/s: 5.0
-
Component/s: None
-
Labels:None
-
Environment:Multiple environments, see Description
Description
For the attached file I've observed the following behavior:
* Windows-based PC with 8 Gb RAM and Sun SDK 6
- Adobe Reader consumes ~40 Mb RAM
- IcePdf Viewer app consumes ~500 Mb RAM and displays the image only after a series of window switching and resizing
- my application invoking Document.getPageImage() (to PNG) consumes ~ 1 Gb RAM during first conversion and the amount grows after each subsequent attempt, though I never made it fail totally
* Windows-based PC with 2 Gb RAM and Sun SDK 6
- my application consumes ~ 500 Mb RAM and converts the PDF file to an empty white rectangle in PNG. No exceptions are thrown, no warnings are displayed (or may be I don't know where to look for warnings)
* Linux-based server with 1Gb RAM, 512 Mb available for the app, Sun SDK 6
- the same white rectangle with no other visible symptoms
The code is as follows (it's Scala not Java but I think it's understandable):
System.setProperty("org.icepdf.core.scaleImages", "false")
GraphicsRenderingHints.getDefault.reset
val doc = new Document()
doc.setByteArray(bytes.toArray, 0, bytes.length, "image.pdf") //bytes.toArray gives us a correct Java byte[] with the whole PDF file there
val image = doc.getPageImage(0, GraphicsRenderingHints.SCREEN, Page.BOUNDARY_CROPBOX, 0f, 2.0f).asInstanceOf[RenderedImage]
val pngStream = new ByteArrayOutputStream()
ImageIO.write(image, "png", pngStream)
repository.setImage(id, Some(pngStream.toByteArray)) //it stores the resulting stream somewhere, not very important for the case I guess
pngStream.close
* Windows-based PC with 8 Gb RAM and Sun SDK 6
- Adobe Reader consumes ~40 Mb RAM
- IcePdf Viewer app consumes ~500 Mb RAM and displays the image only after a series of window switching and resizing
- my application invoking Document.getPageImage() (to PNG) consumes ~ 1 Gb RAM during first conversion and the amount grows after each subsequent attempt, though I never made it fail totally
* Windows-based PC with 2 Gb RAM and Sun SDK 6
- my application consumes ~ 500 Mb RAM and converts the PDF file to an empty white rectangle in PNG. No exceptions are thrown, no warnings are displayed (or may be I don't know where to look for warnings)
* Linux-based server with 1Gb RAM, 512 Mb available for the app, Sun SDK 6
- the same white rectangle with no other visible symptoms
The code is as follows (it's Scala not Java but I think it's understandable):
System.setProperty("org.icepdf.core.scaleImages", "false")
GraphicsRenderingHints.getDefault.reset
val doc = new Document()
doc.setByteArray(bytes.toArray, 0, bytes.length, "image.pdf") //bytes.toArray gives us a correct Java byte[] with the whole PDF file there
val image = doc.getPageImage(0, GraphicsRenderingHints.SCREEN, Page.BOUNDARY_CROPBOX, 0f, 2.0f).asInstanceOf[RenderedImage]
val pngStream = new ByteArrayOutputStream()
ImageIO.write(image, "png", pngStream)
repository.setImage(id, Some(pngStream.toByteArray)) //it stores the resulting stream somewhere, not very important for the case I guess
pngStream.close
The Image in question is quite large requiring quite a bit of memory just to create it. Couple things to keep in mind.