如何控制 PdfPCell 中行之间的间距?
How can I control spacing between lines within a PdfPCell?
我正在尝试使用 itext 5.5.9 为大学成绩单生成 PDF。我决定使用 PdfPTable 来控制布局。文档的开头包含一个概述部分,其中包含以下几行:
姓名:
出生日期:
专业:
未成年人:
现在,输出在这些行之间添加了比预期更多的 space。 (看起来好像这些行是双 spaced。)以下是看起来相关的代码片段:
PdfPCell overviewCell = new PdfPCell();
//other codes here...
overviewCell.setPadding(0f);;
overviewCell.setLeading(0f, 0f);
overviewCell.addElement(new Phrase("Name:", normalFont));
overviewCell.addElement(Chunk.NEWLINE);
overviewCell.addElement(new Phrase("Date of Birth:", normalFont));
overviewCell.addElement(Chunk.NEWLINE);
overviewCell.addElement(Chunk.NEWLINE);
overviewCell.addElement(new Phrase("Major:", normalFont));
我还尝试获取 PdfWriter 的 ColumnText (ct)
,并在调用 overviewCell.setColumn(ct)
之前直接使用该对象,但这也没有修复间距。
请告诉我如何控制单元格内文本的行间距。
谢谢!
为什么不直接添加创建一个子项 table 并将其添加到包含您想要的金额的概览单元格中。这将为您处理大量格式设置。
private static final String _name = "Name:";
private static final String _dateOfBirth = "Date Of Birth:";
private static final String _major = "Major:";
PdfPTable table = new PdfPTable(2);
PdfPCell spaceCell = new PdfPCell(new Phrase(" ", normalFont));
PdfPCell nameCell = new PdfPCell(new Phrase(_name, normalFont));
PdfPCell dateOfBirthCell = new PdfPCell(new Phrase(_dateOfBirth, normalFont));
PdfPcell majorCell = new PdfPCell(new Phrase(_major, normalFont));
table.addCell(nameCell);
table.addCell(spaceCell);
table.addCell(dateOfBirthCell);
table.addCell(spaceCell);
table.addCell(spaceCell); // if you want an extra line break here a fill a line
table.addCell(spaceCell); // with space cells
table.addCell(majorCell);
overviewCell.addElement(table);
我正在尝试使用 itext 5.5.9 为大学成绩单生成 PDF。我决定使用 PdfPTable 来控制布局。文档的开头包含一个概述部分,其中包含以下几行:
姓名: 出生日期:
专业: 未成年人:
现在,输出在这些行之间添加了比预期更多的 space。 (看起来好像这些行是双 spaced。)以下是看起来相关的代码片段:
PdfPCell overviewCell = new PdfPCell();
//other codes here...
overviewCell.setPadding(0f);;
overviewCell.setLeading(0f, 0f);
overviewCell.addElement(new Phrase("Name:", normalFont));
overviewCell.addElement(Chunk.NEWLINE);
overviewCell.addElement(new Phrase("Date of Birth:", normalFont));
overviewCell.addElement(Chunk.NEWLINE);
overviewCell.addElement(Chunk.NEWLINE);
overviewCell.addElement(new Phrase("Major:", normalFont));
我还尝试获取 PdfWriter 的 ColumnText (ct)
,并在调用 overviewCell.setColumn(ct)
之前直接使用该对象,但这也没有修复间距。
请告诉我如何控制单元格内文本的行间距。
谢谢!
为什么不直接添加创建一个子项 table 并将其添加到包含您想要的金额的概览单元格中。这将为您处理大量格式设置。
private static final String _name = "Name:";
private static final String _dateOfBirth = "Date Of Birth:";
private static final String _major = "Major:";
PdfPTable table = new PdfPTable(2);
PdfPCell spaceCell = new PdfPCell(new Phrase(" ", normalFont));
PdfPCell nameCell = new PdfPCell(new Phrase(_name, normalFont));
PdfPCell dateOfBirthCell = new PdfPCell(new Phrase(_dateOfBirth, normalFont));
PdfPcell majorCell = new PdfPCell(new Phrase(_major, normalFont));
table.addCell(nameCell);
table.addCell(spaceCell);
table.addCell(dateOfBirthCell);
table.addCell(spaceCell);
table.addCell(spaceCell); // if you want an extra line break here a fill a line
table.addCell(spaceCell); // with space cells
table.addCell(majorCell);
overviewCell.addElement(table);