0

i have a problem with reading PDF file content in java using itextpdf.jar ,

if i read a small sized(5-15MB) PDF file means its working well, it is possible to read it's contents

but when i read large sized(200MB) PDF file means its showing Run time exception like following

enter code hereException in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2786)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:94)
at com.itextpdf.text.pdf.RandomAccessFileOrArray.InputStreamToArray(RandomAccessFileOrArray.java:213)
at com.itextpdf.text.pdf.RandomAccessFileOrArray.<init>(RandomAccessFileOrArray.java:203)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:235)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:246)
at general.FileStreamClose.main(FileStreamClose.java:28)

Java Result: 1enter code here

any solution for this , how to increase heap size in tomcat

kark
  • 4,763
  • 6
  • 30
  • 44

3 Answers3

0

You can tune your Java Application Runtime settings:

maximize heap size to high value with -Xmx say 500M

tune -XX:MaxHeapFreeRatio and -XX:MinHeapFreeRatio to make sure that the application will not becomes irresponsive when consuming lot of memory when the heap reduces.

TheWhiteRabbit
  • 15,480
  • 4
  • 33
  • 57
0

to increase heap size for tomcat you'll have to set the evnirenment variable JAVA_OPTS and have it contain the -Xmx option for example -Xmx512m

here is a sample script how you can run tomcat

@echo off
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_33
set CATALINA_HOME=C:\Program Files\apache-tomcat-7.0
set JAVA_OPTS=-XX:MaxPermSize=128m -Xmx512m -server
call %CATALINA_HOME%\bin\catalina.bat run
A4L
  • 17,353
  • 6
  • 49
  • 70
0

for additional info, as far as i know, if your machine is 32 bit increase xmx and xms heap size will limited around 1k++. If you need more than that you need to install java 64 bit (of course in 64 machine and 64 OS).

Daniel Robertus
  • 1,100
  • 1
  • 11
  • 24