If one row won't fit on a page, you need to break it up somehow.  And it
sounds like you're setting yourself up for a "640kb ought to be enough
for anyone" problem.  You'll always find a bigger dataset somewhere.

So how do you detect when your data is too big?  IIRC, there's at least
one way to check for "does my table fit".  Lets see... It depends on
what kind of table you're using.  Is it a com.itextpdf.text.Table, or a
com.itextpdf.text.pdf.PdfPTable?

Table has isCellsFitPage(), and isTableFitsPage().  

PdfPTable has... calculateHeightsFast() getRowHeight(),
getTotalHeight().  PdfPTable also has a couple attributes you can use to
control how iText handles situations like this: setExtendLastRow(),
setSplitRows(), setSplitLate().

Rather than stretching the page (which iText won't let you do after
you've started a given page), you can shrink the text.  

        if(rowText.length() > TOO_BIG)
                rowParagraph.setFont( smallerFont );

You could get relatively fancy and use several different font sizes
depending on just how much text there was.  And this would be a good
time to start using a fixed-width font if you can... Take all the
guesswork out of what TOO_BIG will be.  Note that there are limits to
how small the font can get before it's illegible.  Some document types
have legal restrictions on how small the font can be as well.  The "fine
print" can only get so fine.

--Mark Storer
  Senior Software Engineer
  Cardiff.com
 
import legalese.Disclaimer;
Disclaimer<Cardiff> DisCard = null;
 
 

> -----Original Message-----
> From: olive_deb [mailto:[email protected]] 
> Sent: Friday, August 27, 2010 2:01 AM
> To: [email protected]
> Subject: [iText-questions] Malformed PDF table if single a 
> row does not fitin single page.
> 
> 
> Hi,
> 
> I am retrieving XML data from database,Parsing the XML using 
> a SAX Parser and writing the records in the form of Table in 
> PDF using iText.
> 
> Now my XML can be very large , I am using seperate table per 
> page.I am using the following snippet after adding a row.
> 
> if (writer.fitsPage(table) == false) {// check if resulting
>                               // table fits in a page
>       table.deleteLastRow();
>       document.add(table);
>       document.newPage();
>       document.add(new Paragraph("\n"));
>       table = getTable();
> }
> This means that if after adding a particular row,the 
> resulting table does not fit a page ,the last added row is 
> deleted(I am storing its contents in a StringBuffer).Then a 
> new Table is created in a new page ,the stored row is written 
> and the writing the remaining rows in continued.
> 
> But now ,my problem is on of my rows is so large that it does 
> not fit on a single page.And thus the PDF table is malformed 
> in some pages.
> 
> I found one solution ,that is if I change the page size from 
> A4 to A3,the problem is solved and the row now fits a single 
> page.But is there any other solutuion? Please Help
> 
> Regards,
> Olive
> --
> View this message in context: 
> http://itext-general.2136553.n4.nabble.com/Malformed-PDF-table
-if-single-a-row-does-not-fit-in-single-page-> tp2340797p2340797.html
> Sent from the iText - General mailing list archive at Nabble.com.
> 
> --------------------------------------------------------------
> ----------------
> Sell apps to millions through the Intel(R) Atom(Tm) Developer 
> Program Be part of this innovative community and reach 
> millions of netbook users worldwide. Take advantage of 
> special opportunities to increase revenue and speed 
> time-to-market. Join now, and jumpstart your future.
> http://p.sf.net/sfu/intel-atom-d2d
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
> 
> Buy the iText book: http://www.itextpdf.com/book/ 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/
> 
> 
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 9.0.851 / Virus Database: 271.1.1/3091 - Release 
> Date: 08/26/10 11:34:00
> 

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
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/

Reply via email to