需要通过 android 应用制作 PDF 示例,其中框作为 table 列

Need to make PDF sample with boxes as table columns by android app

我需要制作如下图所示的 PDF 示例文件,但我没有找到任何合适的指南来完全按照此操作。我关注了一些 links

http://itextpdf.com/examples/iia.php?id=102

Is there a way to draw a rectangle into a PdfPCell in iText (the Java version)?

但是从第二个开始link我不明白我怎样才能更有可能满足我的要求。

提前致谢。

我不清楚你为什么提到这个例子:http://itextpdf.com/examples/iia.php?id=102 使用该示例创建的 PDF 显示我穿着超人装束。创建带有圆角边框的 table 的 link 是什么?

请看NestedTableRoundedBorder example. It creates a PDF that looks like this: nested_table_rounded_border.pdf

此结构由嵌套的 table 组成。外面的table只有一列,但我们用它来创建圆角:

class RoundRectangle implements PdfPCellEvent {
    public void cellLayout(PdfPCell cell, Rectangle rect,
            PdfContentByte[] canvas) {
        PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
        cb.roundRectangle(
            rect.getLeft() + 1.5f, rect.getBottom() + 1.5f, rect.getWidth() - 3,
            rect.getHeight() - 3, 4);
        cb.stroke();
    }
}

这个cell事件是这样使用的:

cell = new PdfPCell(innertable);
cell.setCellEvent(roundRectangle);
cell.setBorder(Rectangle.NO_BORDER);
cell.setPadding(8);
outertable.addCell(cell);

内部的 tables 用于创建带边框或不带边框的单元格,例如:

// inner table 1
PdfPTable innertable = new PdfPTable(5);
innertable.setWidths(new int[]{8, 12, 1, 4, 12});
// first row
// column 1
cell = new PdfPCell(new Phrase("Record Ref:"));
cell.setBorder(Rectangle.NO_BORDER);
innertable.addCell(cell);
// column 2
cell = new PdfPCell(new Phrase("GN Staff"));
cell.setPaddingLeft(2);
innertable.addCell(cell);
// column 3
cell = new PdfPCell();
cell.setBorder(Rectangle.NO_BORDER);
innertable.addCell(cell);
// column 4
cell = new PdfPCell(new Phrase("Date: "));
cell.setBorder(Rectangle.NO_BORDER);
innertable.addCell(cell);
// column 5
cell = new PdfPCell(new Phrase("30/4/2015"));
cell.setPaddingLeft(2);
innertable.addCell(cell);
// spacing
cell = new PdfPCell();
cell.setColspan(5);
cell.setFixedHeight(3);
cell.setBorder(Rectangle.NO_BORDER);
innertable.addCell(cell);

如果某些尺寸非常符合您的要求,更改宽度数组、填充、固定高度等参数就足够了