Hello,

        I've a PdfPTable with a PdfPCell (with absolute height, no padding)
inside. In the cell there is a Phrase. The Phrase is aligned with
PdfPCell.setVerticalAlignment(). Everything is all right as long as there
isn't a leading.
        After calling the function PdfPCell.setLeading(x, 0) with alignment
middle or top the text isn't in the middle/top but there is an additional
space above the text.
        Why is this so and how is the space calculated? My goal is to place
the text with leading in the middle and the first line directly on top
respectively.

Following code gives an example:

public static void main(String[] args) {
    Document document = new Document();

    try {
        PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("leading_alignment.pdf"));

        document.open();

        PdfContentByte cb = writer.getDirectContent();

        float x = 25;
        float y = 800;
        float width;
        float height;

        for (int i = 1; i <= 4; i++) {
            PdfPTable table = new PdfPTable(1);
            table.getDefaultCell().setPadding(0);
            table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
            table.setTotalWidth(130);

            Phrase phrase = new Phrase("my Text\nnext line",
FontFactory.getFont(FontFactory.HELVETICA, 30f));

            PdfPCell cell = new PdfPCell(phrase);
            cell.setPadding(0);
            cell.setFixedHeight(300);
            cell.setBorderWidth(.1f);
            cell.setBorder(PdfPCell.BOX);

            if (i == 1) {
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            } else if (i == 2) {
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                cell.setLeading(60, 0);
            } else if (i == 3) {
                cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
            } else if (i == 4) {
                cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
                cell.setLeading(60, 0);
            }

            table.addCell(cell);
            table.writeSelectedRows(0, 1, x, y, cb);
            x = x + 140;
        }

        // middleline of the first two cells
        cb.moveTo(25, 650);
        cb.setColorStroke(Color.BLACK);
        cb.setLineWidth(1f);
        cb.lineTo(295, 650);
        cb.stroke();

        document.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}



Thanks for your help!


Best regards,

Martin
BEGIN:VCARD
VERSION:2.1
N:Resch;Martin
FN:Martin Resch ([EMAIL PROTECTED])
ORG:adaptions GmbH
TEL;WORK;VOICE:+49 (08031) 35638 - 37
ADR;WORK:;;Kunstmühlstr. 17;Rosenheim;Bayern;83026;Deutschland
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:Kunstm=FChlstr. 17=0D=0ARosenheim, Bayern 83026=0D=0ADeutschland
URL;WORK:http://www.adaptions.de
EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
REV:20040512T101154Z
END:VCARD

Reply via email to