I'm building a table via a database in Itextsharp with PDFPTable, and the requirements are that no rows/cells in the table have a top or bottom bottom border, but the left and right sides of each cell have a black border (in other words, each column has a left a right border), and the bottom of the table needs to be closed off with a black border as well, which is where my problem lies.
What I'm doing is setting the border to 0, then manually assign borders so that I only get the left and right borders on each cell, as seen below as an example of a "Quantity" column being generated:
cell = new PdfPCell(new Phrase(Qty.value, subheaderFont));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.BackgroundColor = new iTextSharp.text.BaseColor(220, 220, 220);
cell.Border = 0;
cell.BorderColorLeft = BaseColor.BLACK;
cell.BorderWidthLeft = .5f;
cell.BorderColorRight = BaseColor.BLACK;
cell.BorderWidthRight = .5f;
table.AddCell(cell);
The issue is obviously I have no way of detecting the last row to add the border-bottom, but I imagine there has to be a way to control the border of the "table" itself, or am I taking the wrong approach to this?
As you found, PdfPTable doesn't have borders, probably because PDF's don't have tables in the first place. It probably just made more sense to put the borders on the PdfPCell directly (even though PDFs don't support those, either). A table is just a collection of cells, anyway, so let them deal with it.
Anyway, the solution is to set the TableEvent on your instance of the PdfPTable class. To do this you'll need a custom implementation of the IPdfPTableEvent interface. The below code should generally do this for you (see the notes at the bottom for "generally")
class TopBottomTableBorderMaker : IPdfPTableEvent {
private BaseColor _borderColor;
private float _borderWidth;
/// <summary>
/// Add a top and bottom border to the table.
/// </summary>
/// <param name="borderColor">The color of the border.</param>
/// <param name="borderWidth">The width of the border</param>
public TopBottomTableBorderMaker(BaseColor borderColor, float borderWidth ) {
this._borderColor = borderColor;
this._borderWidth = borderWidth;
}
public void TableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) {
//widths (should be thought of as x's) is an array of arrays, first index is for each row, second index is for each column
//The below uses first and last to calculate where each X should start and end
var firstRowWidths = widths[0];
var lastRowWidths = widths[widths.Length - 1];
var firstRowXStart = firstRowWidths[0];
var firstRowXEnd = firstRowWidths[firstRowWidths.Length - 1] - firstRowXStart;
var lastRowXStart = lastRowWidths[0];
var lastRowXEnd = lastRowWidths[lastRowWidths.Length - 1] - lastRowXStart;
//heights (should be thought of as y's) is the y for each row's top plus one extra for the last row's bottom
//The below uses first and last to calculate where each Y should start and end
var firstRowYStart = heights[0];
var firstRowYEnd = heights[1] - firstRowYStart;
var lastRowYStart = heights[heights.Length - 1];
var lastRowYEnd = heights[heights.Length - 2] - lastRowYStart;
//Where we're going to draw our lines
PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
//I always try to save the previous state before changinge anything
canvas.SaveState();
//Set our line properties
canvas.SetLineWidth(this._borderWidth);
canvas.SetColorStroke(this._borderColor);
//Draw some rectangles
canvas.Rectangle(
firstRowXStart,
firstRowYStart,
firstRowXEnd,
firstRowYEnd
);
//They aren't actually drawn until you stroke them!
canvas.Stroke();
canvas.Rectangle(
lastRowXStart,
lastRowYStart,
lastRowXEnd,
lastRowYEnd
);
canvas.Stroke();
//Restore any previous settings
canvas.RestoreState();
}
}
Using it is very easy, just bind an instance to the property:
//Create your name as you normally do
var table = new PdfPTable(3);
//Bind and instance with properties set
table.TableEvent = new TopBottomTableBorderMaker(BaseColor.BLACK, 0.5f);
//The rest is the same
for (var i = 0; i < 6; i++) {
var cell = new PdfPCell(new Phrase(i.ToString()));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.BackgroundColor = new iTextSharp.text.BaseColor(220, 220, 220);
cell.Border = 0;
cell.BorderColorLeft = BaseColor.BLACK;
cell.BorderWidthLeft = .5f;
cell.BorderColorRight = BaseColor.BLACK;
cell.BorderWidthRight = .5f;
table.AddCell(cell);
}
Above I said "generally" it should work. If you have table headers and/or footers, however, you're going to need to take those into account, too. This shouldn't be too hard but you'll need to adjust the y values accounting for table.HeaderRows and table.FooterRows.
I have experienced the same issue found the following solution.
From "iText In Action Second Edition"
PdfPCell extends Rectangle, inheriting a plethora of methods to change the way borders are drawn and backgrounds are painted..
The method "DisableBorderSide(int Rectangle)" is how to go about removeing borders with any other sizing involved.
PdfPCell cell = new PdfPCell(new Phrase("Some Text", FontFactory.GetFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 13, Font.NORMAL, BaseColor.BLACK)));
cell.BackgroundColor = new BaseColor(255, 255, 255);
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.BorderColor = BaseColor.BLACK;
cell.Border = Rectangle.BOX;
cell.BorderWidth = 1;
cell.DisableBorderSide(Rectangle.TOP_BORDER);
cell.DisableBorderSide(Rectangle.BOTTOM_BORDER);
cell.Padding = 3;
table.AddCell(cell);
I solved this using nested tables
'CREATE TWO PDFPTABLES
Dim tblNested1 As New PdfPTable(1)
Dim tblNested2 As New PdfPTable(3)
'CREATE CELLS WITH NO BORDER AND ADD THEM TO TABLE2
Dim cellNested1 = New PdfPCell(New Phrase("CELL1"))
cellNested1.Border = 0
tblNested2.AddCell(cellNested1)
Dim cellNested2 = New PdfPCell(New Phrase("CELL2"))
cellNested2.Border = 0
tblNested2.AddCell(cellNested2)
Dim cellNested3 = New PdfPCell(New Phrase("CELL3"))
cellNested3.Border = 0
tblNested2.AddCell(cellNested3)
'APPEND TABLE2 TO A CELL WITH DEFAULT BORDER
Dim cell1 As New PdfPCell
cell1.AddElement(tblNested2)
tblNested1.AddCell(cell1)
document.Add(tblNested1)
var Rectangular = new Rectangle(56, 621, 540,385);
Rectangular.BorderWidthLeft = 0.1f;
Rectangular.BorderWidthRight = 0.1f;
Rectangular.BorderWidthTop = 0.1f;
Rectangular.BorderWidthBottom = 0.1f;
cb.Rectangle(Rectangular);
cb.Stroke();
Related
Is it possible to make the border length of a specific table cell fit the contents of that cell?
I did
PdfPCell cell = new PdfPCell(new Phrase(total.ToString(),myFont));
cell.Border=PdfPCell.BOTTOM_BORDER | PdfPCell.TOP_BORDER;
cell.HorizontalAlignment=Element.ALIGN_LEFT;
tabl.AddCell(cell);
But it produces the below result (the top & bottom border exceeds the cell data length/space)
Can someone help?
iText 7
In iText 7, this is very straightforward, because it's possible out of the box to set borders to any element. In this use case, instead of using table or cell borders, it's easier to set a top and bottom border to the piece of text itself.
Table table = new Table(4);
table.SetWidth(UnitValue.CreatePercentValue(100));
// no border on the table
table.SetBorder(null);
// no border on the cell
Cell cell = new Cell().SetBorder(null);
Text t = new Text("410.40");
// top and bottom border on the Text instance
t.SetBorderTop(new SolidBorder(1.5f));
t.SetBorderBottom(new SolidBorder(1.5f));
Paragraph p = new Paragraph().Add(t);
cell.Add(p);
table.AddCell(cell);
// some test cells
table.AddCell(new Cell().Add(new Paragraph("Column 2")).SetBorder(null));
table.AddCell(new Cell().Add(new Paragraph("C 3")).SetBorder(null));
table.AddCell(new Cell().Add(new Paragraph("C 4")).SetBorder(null));
doc.Add(table);
iText 5 / iTextSharp
A bit more grunt work is involved to get the same effect. A possible approach is to use a page event listener and a Chunk with a "generic tag" to trigger a page event upon rendering. That callback will expose the rendering rectangle of the Chunk, which allows those coordinates to be used to draw the top and bottom line at the correct location.
writer.PageEvent = new BorderEvent();
PdfPTable table = new PdfPTable(4);
table.WidthPercentage = 100;
PdfPCell cell = new PdfPCell();
// Use a Chunk with a "generic tag", which triggers a callback when it's rendered
Chunk c = new Chunk("410.40");
c.SetGenericTag("borders");
cell.AddElement(c);
// no border on the cell
cell.Border = 0;
table.AddCell(cell);
// some test cells
cell = new PdfPCell();
cell.AddElement(new Paragraph("Column 2"));
cell.Border = 0;
table.AddCell(cell);
cell = new PdfPCell();
cell.AddElement(new Paragraph("C 3"));
cell.Border = 0;
table.AddCell(cell);
cell = new PdfPCell();
cell.AddElement(new Paragraph("C 4"));
cell.Border = 0;
table.AddCell(cell);
doc.Add(table);
The callback for the generic tag:
class BorderEvent : PdfPageEventHelper
{
public override void OnGenericTag(PdfWriter writer, Document document,
Rectangle rect, String text)
{
PdfContentByte canvas = writer.DirectContent;
// draw the top border, based on the rendering rectangle
canvas.SetLineWidth(1.5);
canvas.MoveTo(rect.Left, rect.Top);
canvas.LineTo(rect.Right, rect.Top);
// draw the bottom border, based on the rendering rectangle
// the bottom coordinate is the base line of the text,
// so some calculation, probably including the font size, is
// needed to lower it a bit
// I've used a quick and dirty 3 points here
canvas.Stroke();
canvas.MoveTo(rect.Left, rect.Bottom - 3);
canvas.LineTo(rect.Right, rect.Bottom - 3);
canvas.Stroke();
}
}
I have a given table with 2 columns which I try to export to pdf.
This is my code:
PdfPTable tableUebersicht = new PdfPTable(dtUebersicht100.Columns.Count);
tableUebersicht.SetWidths(new float[] { 250, 420 });
tableUebersicht.LockedWidth = true;
tableUebersicht.TotalWidth = 500f;
foreach (DataColumn c in dtUebersicht100.Columns)
{
PdfPCell Spalte = new PdfPCell(new Phrase(c.ColumnName, VerdanaFont));
Spalte.HorizontalAlignment = Element.ALIGN_CENTER;
Spalte.VerticalAlignment = Element.ALIGN_MIDDLE;
table.AddCell(Spalte);
}
foreach (DataRow dr in dtUebersicht100.Rows)
{
PdfPCell Spalte0 = new PdfPCell(new Phrase(dr[0].ToString(), VerdanaFont));
Spalte0.HorizontalAlignment = Element.ALIGN_CENTER;
Spalte0.VerticalAlignment = Element.ALIGN_MIDDLE;
double Double1 = Convert.ToDouble(dr[1].ToString());
PdfPCell Spalte1 = new PdfPCell(new Phrase(string.Format("{0:C2}", Double1), VerdanaFont));
Spalte1.HorizontalAlignment = Element.ALIGN_RIGHT;
Spalte1.VerticalAlignment = Element.ALIGN_MIDDLE;
table.AddCell(Spalte0);
table.AddCell(Spalte1);
}
table.WriteSelectedRows(0, -1, 35, 757, cb);
The output looks as followed:
As you can see the table direction is from left to right and not from up to down.
I would like to have a table like this where the direction is up to down, on the bottom of the page get up and continue left beside, every second row colored:
overview of the solution
look at the table header, there are 4 columns
generate an iText table object, with 4 columns
add cells in the order left to right, top to bottom
in your case that would be:
Verkaufernummer, Betrag, Verkaufernummer, Betrag
1, 55.04, 50, 3.5
keep track of the row you are currently rendering on, depending on the row, set the background color of the cell (in your logic even vs odd)
I used a following code to create a table in my itextsharp PDF document:
foreach (var subComp in competency.SubCompetensies)
{
cell = new PdfPCell(new Phrase(0, subComp.DescriptionMin, _nfDescr));
cell.Padding = 5;
cell.Rowspan = 2;
table.AddCell(cell);
cell = new PdfPCell(new Phrase(0, subComp.Name, _nfSubComp));
cell.Colspan = 10;
cell.Padding = 5;
table.AddCell(cell);
cell = new PdfPCell(new Phrase(subComp.DescriptionMax, _nfDescr));
cell.Padding = 5;
cell.Rowspan = 2;
table.AddCell(cell);
for (int i = 1; i < 11; i++)
{
cell = new PdfPCell(new Phrase(0, i.ToString(), _nfScale));
cell.FixedHeight = 15f;
cell.Padding = 3;
cell.PaddingLeft = 5;
table.AddCell(cell);
}
}
And here is the result:
As you can see height of cells with numbers is different in every row. It seems that cell.FixedHeight property is ignored.
Is there any way to set fixed height of these cells?
Well, I found a solution. As for me, it seems little pervert, but my deadline doesn't care about how exquisite my code is.
May be somene will find it useful.
Why FixedHeight is ignored?
Because the cells with the numbers drawn last they consume all the free space in a row.
Possible solutions
I can see only two ways:
Obviously, change the order of cells in a row
Render central part of the row by myself
I desided to choose the second way.
Instead of creating therteen cells with rowspans/colspans and adding them to one row, I add only three cells:
cell = new PdfPCell(new Phrase(0, subComp.DescriptionMin, _nfDescr));
cell.MinimumHeight = 50;
cell.Padding = 5;
cell.BorderColor = BaseColor.WHITE;
cell.BackgroundColor = new BaseColor(233, 240, 242);
table.AddCell(cell);
cell = new PdfPCell();
cell.CellEvent = new CellEvents(subComp);
cell.BorderColor = BaseColor.WHITE;
table.AddCell(cell);
cell = new PdfPCell(new Phrase(subComp.DescriptionMax, _nfDescr));
cell.Padding = 5;
cell.BorderColor = BaseColor.WHITE;
cell.BackgroundColor = new BaseColor(233, 240, 242);
table.AddCell(cell);
I add custom cell event to the second sell. It is fired after the cell height is set and before layout rendering. Here is the code of event handler:
private class CellEvents : IPdfPCellEvent
{
public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases)
{
int scoreCellHeight = 20;
var pdfContentByte = canvases[0];
pdfContentByte.SaveState();
pdfContentByte.Rectangle(pos.Left, pos.Bottom + scoreCellHeight, pos.Width, pos.Height - scoreCellHeight);
pdfContentByte.SetColorFill(new BaseColor(233, 240, 242));
pdfContentByte.Fill();
ColumnText ct = new ColumnText(pdfContentByte);
ct.SetSimpleColumn(new Phrase(_model.Name, _nfSubComp), pos.Left, pos.Bottom + 20, pos.Left + pos.Width, pos.Bottom + pos.Height - 5, 10, Element.ALIGN_CENTER);
ct.Go();
float scaleWidth = pos.Width / 10;
for (int i = 1; i < 11; i++)
{
float scaleLeft = pos.Left + (i - 1) * pos.Width / 10;
pdfContentByte.Rectangle(scaleLeft, pos.Bottom, scaleWidth, scoreCellHeight);
pdfContentByte.SetColorFill(i % 2 == 1
? new BaseColor(Color.LightBlue)
: new BaseColor(233, 240, 242));
pdfContentByte.Fill();
ct.SetSimpleColumn(new Phrase(i.ToString(), _nfScale), scaleLeft, pos.Bottom,
scaleLeft + scaleWidth, pos.Bottom + 7, 0, Element.ALIGN_CENTER);
ct.Go();
}
canvases[0].RestoreState();
}
}
I've skipped some details like class constructor and the code, that draws marker (red figures on the screenshot).
Result:
I guess, this workaround is not optimal. But I had to draw a red marker, so I had to handle cell render event, anyway.
Hope, someone can show correct solution.
I have two tables. The outer table is a single column/cell wrapper that I use to paint a gradient background. I then add a nested/child table which is a single row and has three cells.
// set up wrapper table
var wrapperTable = new PdfPTable(1);
wrapperTable .WidthPercentage = 100;
// set up wrapper cell
var wrapperCell = new PdfPCell();
wrapperCell.CellEvent = new GradientBackgroundEvent(writer); // set gradient background
wrapperCell.Border = PdfPCell.NO_BORDER;
// setup nested table
var nestedTable = new PdfPTable(3);
nestedTable.WidthPercentage = 100;
nestedTable.SetWidths(new float[] { 15f, 70f, 15f });
var col1 = new PdfPCell(new Phrase(myText1, font));
col1.VerticalAlignment = Element.ALIGN_TOP;
col1.HorizontalAlignment = Element.ALIGN_CENTER;
col1.Border = PdfPCell.NO_BORDER;
nestedTable.AddCell(col1);
// this is the cell that I'm interested in - borders work, but no bgcolor
var col2 = new PdfPCell(new Phrase(myText2, font));
col2.VerticalAlignment = Element.ALIGN_TOP;
col2.HorizontalAlignment = Element.ALIGN_LEFT;
col2.BackgroundColor = BaseColor.WHITE;
col2.BorderColor = new BaseColor(204, 204, 204);
col2.BorderWidth = 0.2f;
nestedTable.AddCell(col2);
var col3 = new PdfPCell(new Phrase(myText3, font));
col3.VerticalAlignment = Element.ALIGN_TOP;
col3.HorizontalAlignment = Element.ALIGN_CENTER;
col3.Border = PdfPCell.NO_BORDER;
nestedTable.AddCell(col3);
// add nested table to the wrapper table
wrapperCell.AddElement(nestedTable);
I can set the borders for these cells and they paint correctly. However nothing I've tried (short of removing the gradient background) will allow me to see the background color that I've set on a cell in the nested table.
Here is my code to do the gradient fill.
public class GradientBackgroundEvent : IPdfPCellEvent
{
private PdfWriter w;
public GradientBackgroundEvent(PdfWriter w)
{
this.w = w;
}
public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases)
{
var c1 = new BaseColor(238, 238, 238);
var c2 = new BaseColor(221, 221, 221);
PdfShading shading = PdfShading.SimpleAxial(w, position.Left, position.Top, position.Left, position.Bottom, c1, c2);
PdfShadingPattern pattern = new PdfShadingPattern(shading);
ShadingColor color = new ShadingColor(pattern);
PdfContentByte cb = canvases[PdfPTable.BACKGROUNDCANVAS];
position.BackgroundColor = color;
// Fill the rectangle
cb.Rectangle(position);
}
}
I've tried moving code around and changing the order in which the tables/cells are added but that makes no difference because the PDF is drawn at the end (not as it is constructed).
Judging by my debug - it looks to me like the gradient fill is being painted after the background color for the cell is set and effectively overwriting it.
Does anyone have any ideas about how this can be done? Maybe I shouldn't be using a table to achieve this?
I've seen some other posts that suggest using a form field is the way to go. I'd like to avoid this if possible but if it's the only way...
Your background color is getting drawn, unfortunately it is being drawn "under" the gradient background which is why you can't see it. As long as you're only nesting these two tables the simplest solution is probably to just draw your gradient on PdfPTable.BASECANVAS instead of PdfPTable.BACKGROUNDCANVAS.
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);
// Create a new PdfWriter object, specifying the output stream
var output = new MemoryStream();
var writer = PdfWriter.GetInstance(document, output);
document.Open();
PdfPTable table = new PdfPTable(3);
var bodyFont = FontFactory.GetFont("Arial", 10, Font.NORMAL);
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);
Font arial = FontFactory.GetFont("Arial", 6, BaseColor.BLUE);
cell = new PdfPCell(new Phrase("Font test is here ", arial));
cell.PaddingLeft = 5f;
cell.Colspan = 1;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("XYX"));
cell.Colspan = 2;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("Hello World"));
cell.PaddingLeft = 5f;
cell.Colspan = 1;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("XYX"));
cell.Colspan = 2;
table.AddCell(cell);
table.SpacingBefore = 5f;
document.Add(table);
document.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment;filename=Receipt-test.pdf");
Response.BinaryWrite(output.ToArray());
Do I need to specify no borders for individual cells or I can specify no borders for table itself.
Thank you
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.
This should do the trick:
table.DefaultCell.Border = Rectangle.NO_BORDER;
or
table.borderwidth= 0;
First we can set all cell borders as 0 and After assigning all cell to table we can use the following code for for only pdfptable outer border.
PdfPCell cell = new PdfPCell();
cell.AddElement(t);
cell.BorderWidthBottom=1f;
cell.BorderWidthLeft=1f;
cell.BorderWidthTop=1f;
cell.BorderWidthRight = 1f;
PdfPTable t1 = new PdfPTable(1);
t1.AddCell(cell);
Here we can add table to one cell and can set border and again add that cell to another table and we can use as per our requirement.
If your PdfPTable is nested within another PdfPTable, the nested table will show table borders. The only way to get rid of the table borders is to put the nested PdfPTable into a PdfPCell of the main PdfPTable and set the border width of that cell to 0.
iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(1); //<-- Main table
table.TotalWidth = 540f;
table.LockedWidth = true;
float[] widths = new float[] { 540f };
table.SetWidths(widths);
table.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table.SpacingAfter = 10;
PdfPTable bodyTable = new PdfPTable(1); //<--Nested Table
bodyTable.TotalWidth = 540f;
bodyTable.LockedWidth = true;
float[] bodyWidths = new float[] { 540f };
bodyTable.SetWidths(bodyWidths);
bodyTable.HorizontalAlignment = 0;
bodyTable.SpacingAfter = 10;
bodyTable.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER;
var para1 = new Paragraph("This is a long paragraph", blackNormal);
para1.SetLeading(3f, 1f);
PdfPCell bodyCell1 = new PdfPCell();
bodyCell1.AddElement(para1);
bodyCell1.Border = 0;
bodyTable.AddCell(bodyCell1);
iTextSharp.text.pdf.PdfPCell cellBody = new iTextSharp.text.pdf.PdfPCell(bodyTable);
cellBody.BorderWidth = 0; //<--- This is what sets the border for the nested table
table.AddCell(cellBody);
Took me a long time to figure this out. It works for me now.
PdfPTable table = new PdfPTable(4);
table.TotalWidth = 400f;
table.LockedWidth = true;
PdfPCell header = new PdfPCell(new Phrase("Header"));
header.Colspan = 4;
table.AddCell(header);
table.AddCell("Cell 1");
table.AddCell("Cell 2");
table.AddCell("Cell 3");
table.AddCell("Cell 4");
PdfPTable nested = new PdfPTable(1);
nested.AddCell("Nested Row 1");
nested.AddCell("Nested Row 2");
nested.AddCell("Nested Row 3");
PdfPCell nesthousing = new PdfPCell(nested);
nesthousing.Padding = 0f;
table.AddCell(nesthousing);
PdfPCell bottom = new PdfPCell(new Phrase("bottom"));
bottom.Colspan = 3;
table.AddCell(bottom);
doc.Add(table);
PdfPTable table = new PdfPTable(3);
table.TotalWidth = 144f;
table.LockedWidth = true;
table.HorizontalAlignment = 0;
PdfPCell left = new PdfPCell(new Paragraph("Rotated"));
left.Rotation = 90;
table.AddCell(left);
PdfPCell middle = new PdfPCell(new Paragraph("Rotated"));
middle.Rotation = -90;
table.AddCell(middle);
table.AddCell("Not Rotated");
doc.Add(table);
Check this link pls
try this code
yourtable.DefaultCell.Border = 0;