R K Sharma
R K Sharma

Reputation: 855

how to hide the border of table in itext shrp pdf in asp.net MVC vs12?

i am trying to build a pdf, in which i have to add a table without border and i am doing like this, but is there any better way to do this? my code is like this:

 PdfPTable row1 = new PdfPTable(4);
                row1.TotalWidth = 350f;
                row1.LockedWidth = true;
                int[] intTblWidth1 = { 20,50,20,40 };
                row1.SetWidths(intTblWidth1);
                row1.SpacingBefore = 20f;
                row1.HorizontalAlignment = Element.ALIGN_LEFT;
                PdfPCell cel = new PdfPCell(new Phrase("Ordered By: ", bodyFont));
                cel.Colspan = 1;
                cel.Border = 0;
                cel.HorizontalAlignment = 0;
                row1.AddCell(cel);
                PdfPCell cel1 = new PdfPCell(new Phrase(_requester, titleFont));
                cel1.Border = 0;
                cel1.HorizontalAlignment = 0;
                cel1.VerticalAlignment = 0;
                row1.AddCell(cel1);
                PdfPCell cel2 = new PdfPCell(new Phrase("Order #: ", bodyFont));
                cel2.Colspan = 1;
                cel2.Border = 0;
                cel2.HorizontalAlignment = 0;
                row1.AddCell(cel2);
                PdfPCell cel3 = new PdfPCell(new Phrase(_orderNumber, titleFont));
                cel3.Colspan = 1;
                cel3.Border = 0;
                cel3.HorizontalAlignment = 0;
                row1.AddCell(cel3);
                doc.Add(row1);

i am using new table to create new row.

if i do like this:-

PdfPTable table = new PdfPTable(3);
PdfPCell cell = new PdfPCell(new Phrase("Header spanning 3 columns"));
cell.Colspan = 3;
cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table.AddCell(cell);
table.AddCell("Col 1 Row 1");
table.AddCell("Col 2 Row 1");
table.AddCell("Col 3 Row 1");
table.AddCell("Col 1 Row 2");
table.AddCell("Col 2 Row 2");
table.AddCell("Col 3 Row 2");
doc.Add(table);

i am not able to hide the border of table, and i don't wanna any border line in the table. i have to generate a dynamic pdf. any suggestion will be appreciated, i will mark your answer if it work for me. thank you in advance ;) happy coding.

Upvotes: 0

Views: 3757

Answers (1)

Robin Rizvi
Robin Rizvi

Reputation: 5183

Try doing this:

table.DefaultCell.Border = Rectangle.NO_BORDER;

or you should try this for each cell

cellxxx.Border = Rectangle.NO_BORDER;

The Border Elements of the PdfPTable are defined by the PdfPCell which are added to the table. Each Cell will have its own style/formatting. Here is the API: http://api.itextpdf.com/

Upvotes: 1

Related Questions