Hi
i hve a problem with a programm using the itext library.
he throws me an OutOfMemoryError when he calls upon stamper.close(); (marked
by the comment \\erorr). The step before the stamper.close() in the error
propagation is the streams.add(stampPageNumbers(
getMainReportStream(pageEvents)));(marked by // error step before!) which
eclipse tells me. The report is 1810 pages long. Another report that ive
produced, which does NOT give me an OutOfMemoryError, is 1796 pages long.
Ive put the argumens to -Xmx1024m and the print of the ByteArrayOutputStream
gives me"line 488:11103193" (comment :\\size of ByteArrayOutputStream ) . So
the 1024m for the machine should be more than enought. Does anybody has an
idea what the cause of the problem might be?
The code is :
//
private void produceReport()
throws PdfException {
try {
ByteArrayOutputStream reportStream;
// produce report
{
PageTemplatePageEvents pageEvents = new
PageTemplatePageEvents();
Vector<ByteArrayOutputStream> streams =
new Vector<ByteArrayOutputStream>();
streams.add(getAdressCoverPageStream(pageEvents));
streams.add(getReportCoverPageStream(pageEvents));
if(Conf.USE_MANUAL)
streams.add(getImportManualStream(getManualFileName(),
pageEvents));
// error step before!
streams.add(stampPageNumbers(getMainReportStream(pageEvents)));
String pdfTitle = getPdfTitle();
String pdfAuthor =
Conf.getProperty("pdf-properties-author", "");
String pdfSubject =
Conf.getProperty("pdf-properties-subject", "");
String pdfCreator =
Conf.getProperty("pdf-properties-creator", "");
String username = null;
String password = null;
reportStream = getCombinedStream(pdfTitle,
pdfAuthor,
pdfSubject,
pdfCreator,
username,
password,
streams);
}
// add "draft" stamp to the top left corner
// reportStream = addDraftStamp(reportStream);
// add signature
// reportStream = addSignature(reportStream);
// write report to File
String filename = "reports"
+ File.separator
+ getFileName().replaceAll("[^A-Za-z0-9äÄöÖüÜß_.-]", "_");
writeReportToFile(filename, reportStream);
} catch(Exception e) {
e.printStackTrace();
throw new PdfException(getFileName(), e.getMessage()+" "
+(e.getClass().equals(SQLException.class)?((SQLException)e).getNextException().getMessage():""));
}
}
protected ByteArrayOutputStream stampPageNumbers(ByteArrayOutputStream
preoutbytestream)
throws PdfException {
try {
ByteArrayOutputStream outbytestream = new
ByteArrayOutputStream();
\\size of ByteArrayOutputStream
if(Conf.USE_DEBUG){
System.out.println("Size line
488:"+preoutbytestream.size());
}
PdfReader reader = new
PdfReader(preoutbytestream.toByteArray());
PdfStamper stamper = new PdfStamper(reader, outbytestream);
// ensure design by contract: there have to be exactly the same
// number of pages as of footlines.
Logger.log("reader hat " + reader.getNumberOfPages() + "
seiten");
Logger.log("pageFootLines " + pageFootLines.size());
assert(reader.getNumberOfPages()==pageFootLines.size());
int fontsize = 8; // font size of page numbers
for (int page=0; page<pageFootLines.size(); page++ ) {
PdfContentByte over = stamper.getOverContent(page+1);
over.beginText();
over.setFontAndSize(CommonFonts.baseFontInterstateLight,
fontsize);
over.setTextMatrix(reader.getPageSizeWithRotation(page+1).getWidth()
- 1.5f / 2.54f * 72f
- CommonFonts
.baseFontInterstateLight
.getWidthPoint(pageFootLines.elementAt(page),
fontsize), // x
1.0f / 2.54f * 72f); // y
over.showText(pageFootLines.elementAt(page));
over.endText();
}
//Error!
stamper.close();
return outbytestream;
} catch (Exception e) {
e.printStackTrace();
throw new PdfException(getFileName(), e.getMessage()+" "
+(e.getClass().equals(SQLException.class)?((SQLException)e).getNextException().getMessage():""));
}
}
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/