【发布时间】:2021-11-17 01:33:29
【问题描述】:
我在 iText 中有一个表格,可以从我的 Jtable 中添加元素,但是无论有多少单元格,我添加信息的单元格始终位于页面底部,我使用的是 itext 版本 7.1.16。这是我的代码和它的样子
PdfDocument pdf = new PdfDocument(new PdfWriter("/home/user/Desktop/out.pdf"));
Document document = new Document(pdf,PageSize.A4);
PdfFont headFont = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
PdfFont cellFont = PdfFontFactory.createFont(StandardFonts.TIMES_ROMAN);
Table table1 = new Table(5);
table1.setFixedPosition(0f, 0f, 595);
table1.setHeight(550);
table1.addHeaderCell(new Cell()
.setTextAlignment(TextAlignment.CENTER)
.setBackgroundColor(ColorConstants.LIGHT_GRAY)
.add(new Paragraph("Ime"))
.setFont(headFont));
table1.addHeaderCell(new Cell()
.setTextAlignment(TextAlignment.CENTER)
.setBackgroundColor(ColorConstants.LIGHT_GRAY)
.add(new Paragraph("Šifra"))
.setFont(headFont));
table1.addHeaderCell(new Cell()
.setTextAlignment(TextAlignment.CENTER)
.setBackgroundColor(ColorConstants.LIGHT_GRAY)
.add(new Paragraph("Opis"))
.setFont(headFont));
table1.addHeaderCell(new Cell()
.setTextAlignment(TextAlignment.CENTER)
.setBackgroundColor(ColorConstants.LIGHT_GRAY)
.add(new Paragraph("Mjerna Jedinica"))
.setFont(headFont));
table1.addHeaderCell(new Cell()
.setTextAlignment(TextAlignment.CENTER)
.setBackgroundColor(ColorConstants.LIGHT_GRAY)
.add(new Paragraph("Kolicina"))
.setFont(headFont));
for(int i = 0;i<Table.getRowCount();i++){
table1.addCell(new Cell()
.add(new Paragraph(ime.toString()))
.setFont(cellFont)
.setMinHeight(0));
table1.addCell(new Cell()
.add(new Paragraph(sif.toString()))
.setFont(cellFont));
table1.addCell(new Cell()
.add(new Paragraph(op.toString()))
.setFont(cellFont));
table1.addCell(new Cell()
.add(new Paragraph(mj.toString()))
.setFont(cellFont));
table1.addCell(new Cell()
.add(new Paragraph(kol1.toString()))
.setFont(cellFont));
}
【问题讨论】: