2011-09-26 273 views
0

在使用IText生成PDF之前,我需要定位不同的文本。我一直在考慮使用塊,但我不知道如何分開定位它們。我也嘗試使用PdfContentByte,但它不生成任何PDF文件。使用IText for Java進行文本定位

回答

1

爲什麼不把表格與拼塊結合起來用於佈局。例如:

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);