我需要您的帮助才能将双线底部边框仅应用于单元格并删除其他顶部,右侧和左侧边框。我可以使用以下代码实现虚线单元格边框:
class DoubleCell implements PdfPCellEvent {
public void cellLayout(PdfPCell cell, Rectangle position,
PdfContentByte[] canvases) {
PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
canvas.setLineDash(5f, 5f);
canvas.rectangle(position.getLeft(), position.getBottom(),
position.getWidth(), position.getHeight());
canvas.stroke();
}
}
PDF代码是:
Paragraph tableParagraph = new Paragraph();
tableParagraph.setAlignment(Element.ALIGN_CENTER);
PdfPTable table = new PdfPTable(2);
table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
Font total = new Font(Font.TIMES_ROMAN, 16);
PdfPCell cel3a = new PdfPCell(new Paragraph("Total",total));
PdfPCell cel3b = new PdfPCell(new Paragraph("Cell 1",total));
cel3a.setBorder(Rectangle.NO_BORDER);
cel3b.setBorder(Rectangle.NO_BORDER );
cel3b.setCellEvent(new DoubleCell());
table.addCell(cel3a);
table.addCell(cel3b);
tableParagraph.add(table);
所以请协助应用双线底部边框而不使用其他边框。
答案 0 :(得分:1)
在您的代码中,您正在绘制一个矩形:
canvas.rectangle(position.getLeft(), position.getBottom(),
position.getWidth(), position.getHeight());
canvas.stroke();
如果要绘制两条线,则需要绘制两条线:
// construct first line:
canvas.moveTo(position.getLeft(), position.getBottom());
canvas.lineTo(position.getRight(), position.getBottom());
// construct second line (4 user units lower):
canvas.moveTo(position.getLeft(), position.getBottom() - 4);
canvas.lineTo(position.getRight(), position.getBottom() - 4);
// draw lines
canvas.stroke();
如果您希望线条位于不同的位置,请调整position.getBottom()
和position.getBottom() - 4
。您可能还需要在单元格中引入一些额外的填充以适应额外的行。