Text Positioning with IText for Java
I need to position different text before I generate the pdf using IText. I've been thinking of using Chunks, but I don't know how to position them separately. I also tried using PdfContentByte but it doesn't gener开发者_开发百科ate any PDF File.
Why don't you use tables combined with Chunks for your layout. ex:
PdfPTable headerTable = new PdfPTable(2);
float[] headerTableWidths = { 80f, 20f };
headerTable.setWidthPercentage(100f);
headerTable.setWidths(headerTableWidths);
headerTable.getDefaultCell().setBorderWidth(0);
headerTable.getDefaultCell().setPadding(2);
headerTable.getDefaultCell().setBorderColor(BaseColor.BLACK);
headerTable.getDefaultCell().setFixedHeight(90f);
PdfPCell infoCell = new PdfPCell();
infoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
infoCell.setVerticalAlignment(Element.ALIGN_TOP);
infoCell.addElement("test");
infoCell.addElement("text");
table.addCell(infoCell);
精彩评论