________________________________
> Date: Fri, 22 Jan 2010 12:14:20 +0100
> From:
> To: itext-questions@lists.sourceforge.net
> Subject: [iText-questions] java.lang.OutOfMemoryError
>
> 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?
An itext person may have answer off hand but just some general debugging
thoughts.
What precisely is it trying to do when it throws? Expand the underlying byte[]?
If you think it is residual junk, you can look with heap analysis tool and see
what the problem is. In general, if
you are going to make arbitrary length "things" you need to have some means to
swap in and out of memory,
maybe to temp files Usually, long before you run out of allocable memory, you
have run out of physical memory and
effective CPU usage can drop almost to zero as you start thrashing. Trying to
buffer an arbitrary thing completely
in memory will cause a bunch of problems at some point.
Sometimes you can get out of memory conditions due to code or data bugs, for
example if you
want an image buffer and have sizes determined from certain bytes in another
file and file is
wrong format you could get very large w*h etc.
>
> The code is :
>
> //
> private void produceReport()
> throws PdfException {
> try {
>
> ByteArrayOutputStream reportStream;
>
> // produce report
> {
>
> PageTemplatePageEvents pageEvents = new PageTemplatePageEvents();
>
> Vector streams =
> new Vector();
>
> 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> 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():""));
> }
> }
_________________________________________________________________
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
http://clk.atdmt.com/GBL/go/196390706/direct/01/
------------------------------------------------------------------------------
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/