Hi,

I use the latest version of iText 1.4.1, which is a fabulous tool! However today I encountered a rather strange effect. I have declared a Paragrah, and want it to be kept together:

            Paragraph p = new Paragraph();
            p.setSpacingBefore(16);
            p.setSpacingAfter(10);
            p.add(new Chunk("Some Text here", fontUS));

Then I created a PdfPTable:

            PdfPTable table = new PdfPTable(3);
            table.setWidthPercentage(100);
            table.setHorizontalAlignment(Element.ALIGN_TOP);
            table.getDefaultCell().setBorder(0);
            table.getDefaultCell().setHorizontalAlignment( Element.ALIGN_LEFT);

After this I added some Cells. The Table I added to the Paragraph, the Paragraph to the Document. Now the Document started a new page in the middle of the table, which looked very ugly. So I added the command:

            table.setKeepTogether(true);

Now the table was nicely glued together on page 2, but the first Chunk still was on page 1. So I tried to add the the command:

            p.setKeepTogether(true);

to the Paragraph before adding it to the Document. The effect was most strange, because now the first Chunk remained on page 1, while the table was not printed at all , and the Document continued with the next Paragraph on page 2. Deleting the before set table.setKeepTogether(true)-Command didn't help either, the result was still the same. Now I really wonder, how I can keep the whole Paragraph together - The Chunk and the Table?

Any help highly appreciated.

Michael

Reply via email to