Urgent, need itext (pdf generator) + java expert

I am generating pdf using itext from a db source through servlet on weblogic6.1 and displays the pdf back in a webpage. The input for generating the pdf are just a bunch of filters.  I encountered a very strange bug:  java.lang.OutOfMemoryError <<no stack trace available>>

my psuedocode looks like this

new Document   //itext
new table;   //itext

call store proc, add result to table
  same as above  
 same as above
  same as above
  same as above
  same as above


1)if 3 or LESS of those "if" conditions are true everything works perfect.

2)but if 4 or more "if" are true AND one of those is the third "if" AND the input=value1, i get this out of memory error.

3) I can run every single "if" by itself perfectly including with input=value1

4) adding up all the pages using input=value1 it's only about 15 pages, I can generate pdf with 150+ pages with no problem at all using the same servlet/program

5)the pinpoint location of the bug is at doc.add(table). I put 2 debug message one before and one after doc.add(table), the one after (messege2) was never displayed.

6)I used the basic java template found in itext website for pdf generation.

please help if anyone knows why this is happening, i know it will probably take a miracle:)

thank you!


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Have you checked the docs?


It looks like your table may be falling into the category of "very large" (whatever that means).  The recommendation seems to be that you check the fitsPage() method to see if you need to add your own break(s).

This is based on the implication that you are producing a single table that covers several pages.
Sorry.  That last link was from the wrong clipboard buffer :-(

It should have been:

gagaliyaAuthor Commented:
I dont have access to my files right now, but I am confused. I can generate pdf with 150+ pages with no problem using a single table(with a different input value). This input value will only generate a max of 20ish pages and it's giving me out of memory errors, why?
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

What you are trying to do seems to be well within normal memory requirements, so that leads me to think that there may be something recursive happening under certain circumstances (or a circular reference is happening).

Can you check the results of the queries that you perform (especially the third one).  You're probably more interested in the amount of data being added, rather than the actual content.

What does input=value1 represent?
gagaliyaAuthor Commented:
I have a store proc and based on the input to the store proc it spits back different resultsets. A user select inputs from a multi select list in a webpage(each value in the list is the input to the store proc)

so I have the "if"s to match all values listed in the multi select list, whenever it is true it calls the store proc with that value and add the resultset from the store proc to the table.

I checked many times the resultset from the third "if", i really dont see anything different from that resultset vs others, it is actually one of the smaller resultset. And it works as long as there is no more than 3 "if"s equal to true. If a 4th "if" is true, even if its resulset is 1 row, it will give me out of memory error.  
Can you post some code?
gagaliyaAuthor Commented:
okie i found some more weird stuff. this is the function i use to get the table and put the stuff in within each "if". note the comments inside please please.

private static Table getTable(int NumCol) throws BadElementException, DocumentException

       Table datatable = new Table(NumCol);  //numcol=16
                 datatable.setDefaultCellBorder(Rectangle.TOP | Rectangle.BOTTOM);

/***********  If I comment out the addCell(title) codes, everything works****
************  If I dont, i get out of memory error in certain inputs *******/
                                              datatable.addCell(new Phrase("title1", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD)));
                         datatable.addCell(new Phrase("title2", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD)));
                         datatable.addCell(new Phrase("title3", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD)));
                         datatable.addCell(new Phrase("title4" FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD)));
                         datatable.addCell(new Phrase("title16", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD)));


                    Cell spacer = new Cell(new Phrase(" ", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 5, Font.BOLD)));

/***********  If I comment out the addCell(spacer) code, everything works****
************  If I dont, i get out of memory error in certain inputs *******/


                    return datatable;

So If I comment out the add title codes ** OR **  comment out the add spacer code (just adds a blank line after title), eveything works. if i leave BOTH of them in, i get out of memory error on certain inputs.  argg this is so frustrating. Thanks

OK.  Just a quick note to say I'm working on it ;-)

I haven't used iText before, so I've just downloaded it to give it a go.  I have successfully used the code you've posted to create a PDF document with the correct headings (though the numbers 10, 11... wrap).

I'll now add a load of data to see if I can reproduce the problem.  Please post if you know if there are any special circumstances I need to take account of (eg. particularly long entries or odd characters etc.)
Well, I've successfully created documents using your code above with no lines commented out.

I created documents with 100 tables, each table containing 0 .. 5 rows, each row containing 16 cells.  No problems.

I thought there might be an issue if you are adding too many cells to a row, so I re-compiled it to add 18 cells to each row and it worked fine (it just wrapped onto the next row).

When I started, I thought that the problem might be related to where the headers appear on the page (eg. if they are broken across a page boundary), but this doesn't seem to be the case.

Can you provide any more information about the format of the data you are adding?  Do you span across rows or columns at all, or do you just add 16 individual cells to each row?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Have you solved the problem?  What was the solution?
gagaliyaAuthor Commented:
basically, after I format the cells - like making certain columns that has a lot of data wider and the ones with only a few digits narrower. Everything magically worked. I still am clueless as to why it would work, but I have done some regression and load tests and everything works without a hitch.

So to summarize,

1)using the standard equal spacing column width I would get out of memory exceptions and it has nothing to do with the pdf's size
2)after formating my columns, everything would work.

Sorry i didnt post a solution earlier as i dont think i have found one. but hey it works:)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.