gpt4 book ai didi

java - 如何将双线底部边框应用于 iText 中的单元格

转载 作者:行者123 更新时间:2023-11-30 08:03:05 25 4
gpt4 key购买 nike

我需要您的帮助,仅将双线底部边框应用于单元格,并删除其他顶部、右侧和左侧边框。我可以使用以下代码实现虚线单元格边框:

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);

因此,请协助仅应用双线底部边框,而不应用其他边框。

最佳答案

在您的代码中,您正在绘制一个矩形:

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。您可能还想在单元格中引入一些额外的填充以容纳额外的线条。

关于java - 如何将双线底部边框应用于 iText 中的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31588087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com