I've got a problem with iText.
I'm creating PDFs with lots of images, so the Java heap space runs out very easy.
Tried to analyze the dmp with Eclipse Memory Analyzer and found out, that every image uses about 10MB of heap space. But they have only about 350KB on the HD
Is there the chance to flush the heap to the HD and go on with the creation?
Are there other common leaks?
Unfortunately I found nothing useful yet.
That's what the heap looks like for one image
In general I think that added elements remain in cache... how can I get them out?
Is something like this possible?
That's the code as I use it at the time:
Document document = new Document();
PdfWriter writer = null;
try {
writer = PdfWriter.getInstance(document, new FileOutputStream(this.savePath));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
document.open();
Paragraph pdfTitle = new Paragraph();
pdfTitle.add(new Phrase("Title"));
try {
document.add(pdfTitle);
document.add(Chunk.NEWLINE);
} catch (DocumentException e) {
e.printStackTrace();
}
for(int x = 0; x < 10; x++){
//chapter
Paragraph chapterName = new Paragraph("Chapter "+x, FONT[1]);
ChapterAutoNumber chapter = new ChapterAutoNumber(chapterName);
try {
document.add(chapterhapter);
} catch (DocumentException e) {
e.printStackTrace();
}
for(int y = 0; y < 10; y++){
//sec
Paragraph sectionName = new Paragraph("Section "+y, FONT[2]);
Section section = chapter.addSection(sectionName);
for(int z = 0; z < 10; z++){
//subSec
Section subSection = null;
Image image = null;
try {
image = Image.getInstance(path);
} catch (BadElementException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
image.scalePercent(50);
image.setCompressionLevel(9);
Paragraph subDesc = new Paragraph("Desc "+z, FONT[3]);
subSection = section.addSection(subDesc);
picSection.add(image);
try {
document.add(subSection);
} catch (DocumentException e) {
e.printStackTrace();
}
}
}
}
document.close();