Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

java - how can i position content at specified position in itext 7

I just started using this library. How can i position text in a cell at middle and at bottom?

PdfFont font = PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);
Paragraph para = new Paragraph("Test").setFont(font);

Table table = new Table(UnitValue.createPercentArray(1)).useAllAvailableWidth();
Cell cell = new Cell();
cell.setMinHeight(100);
cell.setVerticalAlignment(VerticalAlignment.MIDDLE);
cell.add(para);
cell.add(new Paragraph("test")).setVerticalAlignment(VerticalAlignment.BOTTOM);
table.addCell(cell);

Currently setting the vertical alignment the content is aligned to the bottom. The output:
The output

How can I achieve the position of text at middle and bottom? Like this with in the same cell:

output

Thanks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
    PdfFont font = PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);
    Paragraph para = new Paragraph("Test").setFont(font);

    Table table = new 
    Table(UnitValue.createPercentArray(1)).useAllAvailableWidth();
table.setHorizontalAlignment(HorizontalAlignment.CENTER);
    table.setTextAlignment(TextAlignment.CENTER);

    Cell cell = new Cell();
    cell.setMinHeight(100);
    cell.setVerticalAlignment(VerticalAlignment.MIDDLE);
    cell.add(para);
    cell.add(new Paragraph("test")).setVerticalAlignment(VerticalAlignment.BOTTOM);
    table.addCell(cell);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...