Hiding table border in iTextSharp

前端 未结 6 669
忘了有多久
忘了有多久 2020-12-28 12:03

How can i hide the table border using iTextSharp. I am using following code to generate a file:

var document = new Document(PageSize.A4, 50, 50, 25, 25);

//         


        
6条回答
  •  时光说笑
    2020-12-28 12:49

    Although I upvoted the answer by Martijn, I want to add a clarification.

    Only cells have borders in iText; tables don't have a border. Martijn's suggestion to set the border of the default cell to NO_BORDER is correct:

    table.DefaultCell.Border = Rectangle.NO_BORDER;
    

    But it won't work for the code snippet provided in the question. The properties of the default cell are only used if iText needs to create a PdfPCell instance implicitly (for instance: if you use the addCell() method passing a Phrase as parameter).

    In the code snippet provided by @Brown_Dynamite, the PdfPCell objects are created explicitly. This means that you need to set the border of each of these cells to NO_BORDER.

    Usually, I write a factory class to create cells. That way, I can significantly reduce the amount of code in the class that creates the table.

提交回复
热议问题