ITextSharp: Set table cell border color

前端 未结 1 1103
面向向阳花
面向向阳花 2020-12-31 02:04

How do I set the border color of a table cell. here is the code i have:

// create and define table
var table = new PdfPTable(8);
table.HorizontalAlignment =          


        
1条回答
  •  别那么骄傲
    2020-12-31 02:35

    When you set individual cell border properties you either need to set all border colors and widths individually, or explicitly set the UseVariableBorders property to true. Try this example to see what I mean:

    PdfPTable table = new PdfPTable(1);
    PdfPCell cell = new PdfPCell(new Phrase("test 1"));
    cell.UseVariableBorders = true;
    cell.BorderColorLeft = BaseColor.BLUE;
    cell.BorderColorRight = BaseColor.ORANGE;
    table.AddCell(cell);
    
    cell = new PdfPCell(new Phrase("test 2"));
    cell.BorderColorLeft = BaseColor.RED;
    cell.BorderColorRight = BaseColor.GREEN;
    cell.BorderColorTop = BaseColor.PINK;
    cell.BorderColorBottom = BaseColor.YELLOW;
    cell.BorderWidthLeft = 1f;
    cell.BorderWidthRight = 1f;
    cell.BorderWidthTop = 1f;
    cell.BorderWidthBottom = 1f;
    table.AddCell(cell);
    
    cell = new PdfPCell(new Phrase("test 3"));
    cell.BorderColor = BaseColor.GREEN;
    table.AddCell(cell);
    

    0 讨论(0)
提交回复
热议问题