Solved

Urgent, need itext (pdf generator) + java expert

Posted on 2003-11-19
12
977 Views
Last Modified: 2008-03-10
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

if()
call store proc, add result to table
if()
  same as above  
if()
 same as above
if()
  same as above
if()
  same as above
if()
  same as above

debug(message1)
doc.add(table)
debug(message2)

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!

gaga

0
Comment
Question by:gagaliya
  • 8
  • 4
12 Comments
 
LVL 15

Expert Comment

by:jimmack
ID: 9780262
Have you checked the docs?

http://www.experts-exchange.com/Web/Web_Languages/Q_20799515.html#9780162

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.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9780285
Sorry.  That last link was from the wrong clipboard buffer :-(

It should have been:

http://www.lowagie.com/iText/tutorial/ch05.html#memory
0
 
LVL 1

Author Comment

by:gagaliya
ID: 9780433
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?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 15

Expert Comment

by:jimmack
ID: 9780648
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?
0
 
LVL 1

Author Comment

by:gagaliya
ID: 9780737
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.  
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9780964
Can you post some code?
0
 
LVL 1

Author Comment

by:gagaliya
ID: 9781825
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.setCellsFitPage(true);
                 datatable.setPadding(4);
                 datatable.setSpacing(0);
                 datatable.setWidth(100);
                 datatable.setDefaultHorizontalAlignment(Element.ALIGN_CENTER);
       datatable.setDefaultRowspan(2);
       datatable.setDefaultCellBorderWidth(7);
                 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)));
                                                                ........etc
                         datatable.addCell(new Phrase("title16", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD)));

                    datatable.setDefaultCellBorder(Rectangle.BOX);
                   datatable.setDefaultCellBorderWidth(0);
                   datatable.setDefaultRowspan(1);

                    Cell spacer = new Cell(new Phrase(" ", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 5, Font.BOLD)));
                    spacer.setBorder(Rectangle.NO_BORDER);
                    spacer.setColspan(NumCol);

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

                    datatable.setDefaultCellBorderWidth(1);
                    datatable.endHeaders();

                    datatable.setDefaultHorizontalAlignment(Element.ALIGN_LEFT);
                    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

gaga
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9783241
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.)
0
 
LVL 15

Accepted Solution

by:
jimmack earned 500 total points
ID: 9783364
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?
0
 
LVL 15

Expert Comment

by:jimmack
ID: 10003674
Have you solved the problem?  What was the solution?
0
 
LVL 1

Author Comment

by:gagaliya
ID: 10003987
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:)
0
 
LVL 15

Expert Comment

by:jimmack
ID: 10003994
Thanx.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ejb wildfly example 2 20
How do I remove an object from a 3 40
Bot application - advice 3 38
restrict decimal places for double datatype 10 19
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question