Hi there,
I have a PdfPTable with 6 columns (pos, description, quantity, price,
discount, sum). Most likely the table doesn't fit on one page and must be
split. The SplitLate option of the table is set to false. The splitting
does work with the description column. When the cell doesn't fit on one
page, because the description ist too long, the content of the four right
columns is not in the row of the last description line, but in the last
line of the cell starting page.
Here is a little draft for better understanding:
|Pos|Description |Quantity|Price|Discount|Sum
| | | | | |
| 10|blah text blah | | | | // cell starts
here
| |blah text blah | | | |
| |blah text blah | | | |
| |blah text blah | 2 | 100| 10| 180 // the four right
columns are printed here at the moment
| |---------------|--------|-----|--------|------ // Pagebreak starting
Page 2
| |blah text blah | | | |
| |blah text blah | | | |
| |blah text blah | | | |
| |blah text | 2 | 100| 10| 180 // they should be
printed here; cell ends here
| | | | | |
When the description start is on the same page as its end, it works
correctly (i.e. the four right columns are printed in the row where the
description ends).
Now I want to describe the logic I've implemented to get the layout I
want. I count the amount of description lines and according to the result
insert enough "\n"s to the beginning of the text in the four right rows to
display it in the last row of the description line.
Code snippet of the cell which doesn't work as expected:
****
protected final static float PARAGRAPHSPACING = 1F;
public PdfPCell createCell(String text, Font font, int
horizontalAlignment, int verticalAlignment){
PdfPCell cell = new PdfPCell();
Paragraph parag = null;
// Devide the whole text into its lines
String[] lines = StringUtils.splitPreserveAllTokens(text,'\n');
//(Apache StringUtils)
// for every line in the array create a new Paragraph and set the
spacing and alignment.
// Add the Paragraph (inside one line of text) with addElement method
to cell (composite mode)
for (int i = 0; i < lines.length; i++) {
parag = new Paragraph(lines[i], font);
parag.setSpacingAfter(paragraphspacing);
parag.setAlignment(horizontalAlignment);
cell.addElement(parag);
}
cell.setBorder(Rectangle.LEFT | Rectangle.RIGHT);
cell.setHorizontalAlignment(horizontalAlignment); // sets the same
as inside the loop
cell.setVerticalAlignment(verticalAlignment);
return cell;
}
****
Btw. I'm using iText V1.4.8. If someone needs a compileable example just
say a word and I will create one. I though first try it like this, because
creating one is somehow workintensive for me (pageevents, no application
server etc.).
Have I made a mistake or is it a bug or maybe a feature of iText? I've
read the relevant chapters of iText in Action, but found no solution to my
problem. References to the book are welcome, when you can point me to
anything that leads to a solution.
Thank you very much in advance.
Best regards,
Benjamin Rein
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/