Android如何使用itext设置桌面上的页边空白
我创建了一个带有导出pdf选项的android应用程序,并使用itext插件创建pdf文档。我想设置“表边距顶部”属性,因为它显示在文档顶部。我应该在徽标和表格之间添加段落,还是有其他解决方案 这是我的密码:Android如何使用itext设置桌面上的页边空白,android,itext,Android,Itext,我创建了一个带有导出pdf选项的android应用程序,并使用itext插件创建pdf文档。我想设置“表边距顶部”属性,因为它显示在文档顶部。我应该在徽标和表格之间添加段落,还是有其他解决方案 这是我的密码: private static void createTable(Document document) throws BadElementException { try { PdfPTable table = new PdfPTable(5);
private static void createTable(Document document)
throws BadElementException {
try {
PdfPTable table = new PdfPTable(5);
// t.setBorderColor(BaseColor.GRAY);
// t.setPadding(4);
// t.setSpacing(4);
// t.setBorderWidth(1);
PdfPCell c1 = new PdfPCell(new Phrase("Col2"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
c1.setFixedHeight(20);
table.addCell(c1);
c1 = new PdfPCell(new Phrase("Col2"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
c1.setFixedHeight(20);
table.addCell(c1);
c1 = new PdfPCell(new Phrase("Col3"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
c1.setFixedHeight(20);
table.addCell(c1);
c1 = new PdfPCell(new Phrase("Col4"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
c1.setFixedHeight(20);
table.addCell(c1);
c1 = new PdfPCell(new Phrase("Col5"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
c1.setFixedHeight(20);
table.addCell(c1);
table.setHeaderRows(1);
table.addCell("1.0");
table.addCell("1.1");
table.addCell("1.2");
table.addCell("1.3");
table.addCell("1.4");
table.addCell("2.0");
table.addCell("2.1");
table.addCell("2.2");
table.addCell("2.3");
table.addCell("2.4");
document.add(table);
} catch (Exception e) {
e.printStackTrace();
}
可以使用以下方法将一个表与其余内容分开:
myTable.setSpacingBefore(10);
myTable.setSpacingAfter(15);
使用iText7更新至2021年2月 您可以使用
margin
属性:
myTable.setMarginTop(20);