3

I have to generate large PDF files , which has table with 30000 rows. I have to generate around 40 files which is taking 19 hours. Could any body suggest optimized way for the same. Most of the time taken by document.add(table) method.

I am using ITEXT 5.4

I used features of larElement interface , in my table I have 40 to 96 columns.

I can post the code later. below is pseudo code.

public void createTable(rs,document){
    PdfpTable table = new PdfPTable(96)
    table.setComplete(false);

    int K=1;

    while(rs.next) {

        for(int i=1,i <=columnCount;i++) {

            PdfPCell cell = new PdfPCell();

            Chunk chunk = new Chunk(rs.getString(i))

            cell.addElement(chunk);

            table.addCell(cell)

        }
        k++;
    }

    if(k%==10000) {
        document.add(table);
    }

    table.setComplete(true);
    document.add(table);
}
Chris Haas
  • 53,986
  • 12
  • 141
  • 274
user2844285
  • 31
  • 1
  • 3
  • Without seeing your code we can't help you too much but I _can_ say that that is _*way*_ too long. I just built a 30,000 row table with four columns and it took just a couple of seconds. Check out this post which shows how you can intermittently flush the table to reduce memory consumption which might help you. Its in C# but you should be able to translate it pretty easily. http://stackoverflow.com/a/15483598/231316 – Chris Haas Oct 04 '13 at 13:06
  • @ChrisHaas' sample in his answer uses a 4 column table and you have 40 column tables. In my eyes that indicates that you should flush your tables much earlier than he did. Instead you flush it much later! He chose 1000 lines as breaking point, you 10000. – mkl Oct 05 '13 at 12:09
  • @Ashish-flushing will help me to avoid memory issue. I do not have memory issue. I want to reduce the time. if i reduce the flush count document.add() method wull called more time that will also increase the generation time – user2844285 Oct 05 '13 at 12:19
  • 1
    I might have formatted your code wrong, but as @mkl pretty much said, it looks like you are flushing outside of your loop instead of inside. – Chris Haas Oct 07 '13 at 10:32

0 Answers0