Hey,

First of all, sorry for the double post but I do need the advice and I do
realize that the initial thread got started off on the wrong foot.

I made a unit test to show how I encounter the problem.
Note that the whole document is cut of exactly at the end of the table, so
the table should always fit on one page, however it doesn't.

If I remove the line cell.setPaddingTop(-3) the cutting problem goes away,
but then the space between the cells is way too large.
I do feel something isn't exactly as it should be because the size of the
table is known and hence it should always fit on one page regardless of
padding.  But I might be mistaken of course.


    @Test
    public void testSizeBug() throws DocumentException,
FileNotFoundException {
        PdfPTable main = new PdfPTable(1);
        main.setTotalWidth(350f);
        main.setSpacingAfter(0);
        main.setSpacingBefore(0);

        main.setLockedWidth(true);
        for(int i=0; i < 15; i++){
            Paragraph title = new Paragraph(new Phrase(new Chunk("titel
"+i,FontFactory.getFont(BaseFont.TIMES_ROMAN))));
            Paragraph par = new Paragraph(new Phrase(new Chunk("cell "+i,
FontFactory.getFont(BaseFont.TIMES_ROMAN))));
            par.setSpacingAfter(-1.5f);
            PdfPCell cell = new PdfPCell();
            cell.addElement(title);
            cell.addElement(par);
            Paragraph par2 = new Paragraph(new Phrase(new Chunk("nextline"
,FontFactory.getFont(BaseFont.TIMES_ROMAN))));
            par2.setSpacingAfter(-1.2f);
            applyDefaultCellProps(cell);
            cell.addElement(par2);
            main.addCell(cell);
        }

        Document document = new Document(new Rectangle(350f,
main.getTotalHeight())); //!!
        File file = new File("c:/tmp/sizeTest.pdf");
        FileOutputStream fos = new FileOutputStream(file);
        PdfWriter writer = PdfWriter.getInstance(document, fos);
        document.setMargins(0f,0f,0f,0f);   //eerst, daarna doc openen
        document.open();

        document.add(main);
        document.close();
        writer.close();


    }

    private void applyDefaultCellProps(PdfPCell cell){
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.enableBorderSide(Rectangle.LEFT);
        cell.enableBorderSide(Rectangle.RIGHT);
        cell.setPadding(5);
        cell.setPaddingTop(-3);
        cell.setPaddingBottom(4);
    }
-- 
View this message in context: 
http://itext-general.2136553.n4.nabble.com/PdfPTable-padding-and-spacing-tp2248510p2248510.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
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