Quantcast

Building a pdf with tables that break across multiple pages

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Building a pdf with tables that break across multiple pages

Erik Pfingsten

Problem:

            I need to build PDF’s for a dynamic reporting environment (using iTextSharp in ASP.Net/C# 3.0 environment).  In general the end-user will be able to choose however many fields they would like to show up.  I would like to simulate something like SQL Reporting services where they will get repeating headers on each page, as well as having long rows break across pages (ie when they select 50 fields and the data is say 500 rows of data, the first 10 fields/first 30 rows show on page 1, the next 10 fields/first 30 rows show on page 2, etc through page 5, then the next set of rows 31-60 appears on page 6, etc.

 

My general approach that I am thinking of taking is as follows:

 

Set up a table with the 50 columns

 

calculate approximate column widths by using getWidthPoint on the text in each column of the first row of data

use the columns widths to do SetTotalWidth

 

add my cells to the table

 

use PdfPTable.Size to get the number of rows in the table, then divide that by how many rows I think will fit on a page

 

use WriteSelectedRows(colStart, colEnd, rowStart, rowEnd, xPos, yPos, canvas) to write out x number of columns and n number of rows then do a new page and use WriteSelectedRows with the next batch of columns, do a new page, next set of columns, etc.

 

 

Does this makes sense?  In general is this the “correct” way to go about accomplishing what I need or am I going down a completely wrong path?

 

Also, I have ordered the book and it should be arriving tomorrow, so if the answer is “this exact situation is described in detail in the book, go buy it”, I can live with that too

 

Thank you

 

 

Erik Pfingsten


This message, including any attachments, may contain information
which is confidential and privileged. Unless you are the addressee (or 
authorized to receive for the addressee), you may not read, use, copy 
or disclose to anyone the message, its attachments, or any information 
contained therein. If you have received the message in error, please 
advise the sender by reply e-mail and delete the message and any 
attachments.

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Building a pdf with tables that break across multiple pages

iText mailing list
Erik Pfingsten wrote:
> I would like to simulate something like SQL Reporting services
> where they will get repeating headers on each page, as well as having
> long rows break across pages (ie when they select 50 fields and the data
> is say 500 rows of data, the first 10 fields/first 30 rows show on page
> 1, the next 10 fields/first 30 rows show on page 2, etc through page 5,
> then the next set of rows 31-60 appears on page 6, etc.

That's done automatically, isn't it? See http://1t3xt.be/?X00002a

> My general approach that I am thinking of taking is as follows:
> Set up a table with the 50 columns
> calculate approximate column widths by using getWidthPoint on the text
> in each column of the first row of data

You need to know the column widths in advance; so yes, you probably need
getWidthPoint to achieve this.

> use the columns widths to do SetTotalWidth
> add my cells to the table
> use PdfPTable.Size to get the number of rows in the table, then divide
> that by how many rows I think will fit on a page

I don't think that's necessary, unless you

> use WriteSelectedRows(colStart, colEnd, rowStart, rowEnd, xPos, yPos,
> canvas) to write out x number of columns and n number of rows then do a
> new page and use WriteSelectedRows with the next batch of columns, do a
> new page, next set of columns, etc.

I don't understand why you would need WriteSelectedRows.
Why don't you add the table to the document?
If you need to add the table at absolute positions, wrap
it in a ColumnText object like this: http://1t3xt.be/?X0000a4

> Does this makes sense?  In general is this the "correct" way to go about
> accomplishing what I need or am I going down a completely wrong path?

I think you're making it yourself difficult by using writeSelectedRows.
It's easier to just add the table to the document. That also allows you
to tune the way the content inside the cells is split:
http://1t3xt.be/?X000041

> Also, I have ordered the book and it should be arriving tomorrow, so if
> the answer is “this exact situation is described in detail in the book,
> go buy it”, I can live with that too

You'll recognize the examples mentioned above in chapter 6 of the book ;-)
--
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Building a pdf with tables that break across multiple pages

Erik Pfingsten
Ok, looking back I may not have been clear enough.  I need to split the table vertically (like figure 6.10 in the book)

I have 20 columns, with a total column width of 1000 pts

I am writing out to standard Letter size (Landscape orientation) paper with a total width (forget about margins for now) of (11 inches x 72 points) 792 points.

It seems to me (from the examples I am looking at and samples I have found) if the total column width is larger than the page width I have 3 options.
1) use setWidthPercentage to 100 to squeeze everything into 1 page (which can makes things unreadable)
2) use SetTotalWidth(float[]) to set the total width, which causes the text to run off the right side of the page
3) use WriteSelectedRows to write N columns out to page one and the remaining columns out to page two (as in figure 6.10 in the book)

Document.add just adds the whole table (resulting in 1 or 2 above).

-----Original Message-----
From: 1T3XT info [mailto:[hidden email]]
Sent: Wednesday, April 15, 2009 4:21 AM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Building a pdf with tables that break across multiple pages

Erik Pfingsten wrote:
> I would like to simulate something like SQL Reporting services
> where they will get repeating headers on each page, as well as having
> long rows break across pages (ie when they select 50 fields and the data
> is say 500 rows of data, the first 10 fields/first 30 rows show on page
> 1, the next 10 fields/first 30 rows show on page 2, etc through page 5,
> then the next set of rows 31-60 appears on page 6, etc.

That's done automatically, isn't it? See http://1t3xt.be/?X00002a


> My general approach that I am thinking of taking is as follows:
> Set up a table with the 50 columns
> calculate approximate column widths by using getWidthPoint on the text
> in each column of the first row of data

You need to know the column widths in advance; so yes, you probably need
getWidthPoint to achieve this.

> use the columns widths to do SetTotalWidth
> add my cells to the table
> use PdfPTable.Size to get the number of rows in the table, then divide
> that by how many rows I think will fit on a page

I don't think that's necessary, unless you

> use WriteSelectedRows(colStart, colEnd, rowStart, rowEnd, xPos, yPos,
> canvas) to write out x number of columns and n number of rows then do a
> new page and use WriteSelectedRows with the next batch of columns, do a
> new page, next set of columns, etc.

I don't understand why you would need WriteSelectedRows.
Why don't you add the table to the document?

If you need to add the table at absolute positions, wrap
it in a ColumnText object like this: http://1t3xt.be/?X0000a4

> Does this makes sense?  In general is this the "correct" way to go about
> accomplishing what I need or am I going down a completely wrong path?

I think you're making it yourself difficult by using writeSelectedRows.
It's easier to just add the table to the document. That also allows you
to tune the way the content inside the cells is split:
http://1t3xt.be/?X000041

> Also, I have ordered the book and it should be arriving tomorrow, so if
> the answer is "this exact situation is described in detail in the book,
> go buy it", I can live with that too

You'll recognize the examples mentioned above in chapter 6 of the book ;-)
--
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php


This message, including any attachments, may contain information
which is confidential and privileged. Unless you are the addressee (or
authorized to receive for the addressee), you may not read, use, copy
or disclose to anyone the message, its attachments, or any information
contained therein. If you have received the message in error, please
advise the sender by reply e-mail and delete the message and any
attachments.


------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Building a pdf with tables that break across multiple pages

iText mailing list
Erik Pfingsten wrote:
3) use WriteSelectedRows to write N columns out to page one and the
remaining columns out to page two (as in figure 6.10 in the book)

Note that writeSelectedRows returns a Y position, you could write one
row at a time and decide if a new page is needed after every row (based
on the calculated height of the next row).

4) write the complete table to a larger PdfTemplate using ColumnText;
then add the same PdfTemplate twice, once to the odd pages for the left
part, once to the even pages for the right part.

I'm 99% sure I have an example of 4) somewhere, but it must date from
before I used to put examples on 1t3xt.info and I don't find it anywhere.

I have been answering iText questions the whole day (on and off list).
The fact that I need to spend that much on the mailing list really
compromises the creation of new examples, documentation and new
functionality! And if I don't have the time to write documentation, the
constant flow of questions on the list will never stop.

This isn't a remark aimed at you personally; I was more annoyed by the
stupid question from GE this morning and by some really trivial
questions earlier today. (Your question was actually a good one; if I
had more time, I'd written an example for you.) It's just that my
"working day" is almost over now, and I have the feeling I haven't done
any "real" work; that's very frustrating.
--
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Building a pdf with tables that break across multiple pages

Erik Pfingsten
[Erik Pfingsten] I ended up doing something very similar with WriteSelectedRows (writing one line at a time and checking if I need a new page after each line), but I will read up on the ColumnText option you suggest.

Thanks for the help, it is appreciated

Erik Pfingsten


> -----Original Message-----
> From: 1T3XT info [mailto:[hidden email]]
> Sent: Wednesday, April 15, 2009 10:55 AM
> To: Post all your questions about iText here
> Subject: Re: [iText-questions] Building a pdf with tables that break
> across multiple pages
>
> Erik Pfingsten wrote:
> 3) use WriteSelectedRows to write N columns out to page one and the
> remaining columns out to page two (as in figure 6.10 in the book)
>
> Note that writeSelectedRows returns a Y position, you could write one
> row at a time and decide if a new page is needed after every row (based
> on the calculated height of the next row).
>
> 4) write the complete table to a larger PdfTemplate using ColumnText;
> then add the same PdfTemplate twice, once to the odd pages for the left
> part, once to the even pages for the right part.
>
> I'm 99% sure I have an example of 4) somewhere, but it must date from
> before I used to put examples on 1t3xt.info and I don't find it anywhere.
>
> I have been answering iText questions the whole day (on and off list).
> The fact that I need to spend that much on the mailing list really
> compromises the creation of new examples, documentation and new
> functionality! And if I don't have the time to write documentation, the
> constant flow of questions on the list will never stop.
>
> This isn't a remark aimed at you personally; I was more annoyed by the
> stupid question from GE this morning and by some really trivial
> questions earlier today. (Your question was actually a good one; if I
> had more time, I'd written an example for you.) It's just that my
> "working day" is almost over now, and I have the feeling I haven't done
> any "real" work; that's very frustrating.
> --
> This answer is provided by 1T3XT BVBA
> http://www.1t3xt.com/ - http://www.1t3xt.info
>
> --------------------------------------------------------------------------
> ----
> This SF.net email is sponsored by:
> High Quality Requirements in a Collaborative Environment.
> Download a free trial of Rational Requirements Composer Now!
> http://p.sf.net/sfu/www-ibm-com
> _______________________________________________
> iText-questions mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> Buy the iText book: http://www.1t3xt.com/docs/book.php


This message, including any attachments, may contain information
which is confidential and privileged. Unless you are the addressee (or
authorized to receive for the addressee), you may not read, use, copy
or disclose to anyone the message, its attachments, or any information
contained therein. If you have received the message in error, please
advise the sender by reply e-mail and delete the message and any
attachments.


------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Building a pdf with tables that break across multiple pages

Kiran.Karra
Dear Erik Pfingsten

Please post the solution you found. This will be very helpful for me and many others.

Thanks in advance.
Loading...