How to set only vertical table line in pdf using itext sharp?

I have a table with vertical and horizontal lines. But I do not need a horizontal line. I need only vertical lines. How can I install it. My expected o / p

My table code

PdfPTable table = new PdfPTable(5);
table.TotalWidth = 510f;//table size
table.LockedWidth = true;
table.HorizontalAlignment = 0;
table.SpacingBefore = 10f;//both are used to mention the space from heading


table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(new Phrase(new Phrase("    SL.NO", font1)));

table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(new Phrase(new Phrase("   SUBJECTS", font1)));

table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(new Phrase(new Phrase("   MARKS", font1)));

table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(new Phrase(new Phrase("   MAX MARK", font1)));

table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(new Phrase(new Phrase("   CLASS AVG", font1)));

Doc.Add(table);

Example:

enter image description here

Anyone help

+4
source share
2 answers

You can change the borders of the cells so that they display only vertical lines. How to do this depends on how you add cells to the table.

These are two approaches:

1. You explicitly create PdfPCell objects:

PdfPCell cell = new PdfPCell (); cell.AddElement (new paragraph ("my content")); cell.Border = PdfPCell.LEFT; table.AddCell (cell);

. :

cell.Border = PdfPCell.LEFT | PdfPCell.RIGHT;

2. PdfPCell:

PdfPCell , iTextSharp . DefaultCell, PdfPTable, :

table.DefaultCell.Border = Rectangle.LEFT | Rectangle.RIGHT;
table.addCell("cell 1");
table.addCell("cell 2");
table.addCell("cell 3");

, . , , .

. iTextSharp

:

PdfPTable table = new PdfPTable(5);
table.TotalWidth = 510f;//table size
table.LockedWidth = true;
table.SpacingBefore = 10f;//both are used to mention the space from heading
table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
table.DefaultCell.Border = PdfPCell.LEFT | PdfPCell.RIGHT;
table.AddCell(new Phrase("    SL.NO", font1));
table.AddCell(new Phrase("   SUBJECTS", font1));
table.AddCell(new Phrase("   MARKS", font1));
table.AddCell(new Phrase("   MAX MARK", font1));
table.AddCell(new Phrase("   CLASS AVG", font1));
Doc.Add(table);

DefaultCell . Phrase : new Phrase(new Phrase("content")).

+5

, , , , 2015 , .

PdfPTable table2 = new PdfPTable(8);

.

table2.WidthPercentage = 100;

,

table2.DefaultCell.Border = Rectangle.RIGHT_BORDER;
table2.DefaultCell.Border = Rectangle.LEFT_BORDER;

, , .

table2.AddCell(new Phrase("Total Amount", ftxt));
table2.AddCell(new Phrase("Another text", ftxt));

, , pdf.

doc.Add(table2);

, iTextSharp /, , , .

0

Source: https://habr.com/ru/post/1608926/


All Articles