Im using iTextSharp 5.5.13.2. What my program is doing is generate a new PDF, which will load inside multiple pdfs and a paragraph to each document page. The issue is that I want to make it fit the whole document but is leaving a space, tried multiple ways like:
· Adding a table and two cells makes the first cell fit the full document, the second one is on other page.
· Adding a table and one cell makes a Document Exception.
Working code but happens as said on the first point:
foreach (KeyValuePair<string, string> key in dict)
{
PdfReader reader = new PdfReader(key.Key);
for (int i = 1; i <= reader.NumberOfPages; i++)
{
PdfImportedPage page = writer.GetImportedPage(reader, i);
PdfPTable table = new PdfPTable(1);
table.WidthPercentage = 100;
PdfPCell cell = new PdfPCell(iTextSharp.text.Image.GetInstance(page), true);
cell.Border = iTextSharp.text.Rectangle.NO_BORDER;
//cell.AddElement(new Phrase(key.Value));
PdfPCell cell2 = new PdfPCell(new Phrase(key.Value));
cell2.Border = iTextSharp.text.Rectangle.NO_BORDER;
table.AddCell(cell);
table.AddCell(cell2);
document.Add(table);
document.NewPage();
}
}
How could I solve this? Thanks!
I solved it with this code, what I've done is add both cells to a table and reduce the WidthPercentage so all fit into one page.
foreach (KeyValuePair<string, string> key in dict)
{
PdfReader reader = new PdfReader(key.Key);
for (int i = 1; i <= reader.NumberOfPages; i++)
{
PdfImportedPage page = writer.GetImportedPage(reader, i);
PdfPTable table = new PdfPTable(1);
table.WidthPercentage = 68;
if (key.Value.Contains("word"))
table.WidthPercentage = 65;
PdfPCell cell = new PdfPCell(iTextSharp.text.Image.GetInstance(page), true);
cell.Border = iTextSharp.text.Rectangle.NO_BORDER;
//cell.AddElement(new Phrase(key.Value));
PdfPCell cell2 = new PdfPCell(new Phrase(key.Value));
cell2.Border = iTextSharp.text.Rectangle.NO_BORDER;
table.AddCell(cell);
table.AddCell(cell2);
document.Add(table);
document.NewPage();
}
}
Related
So basically I've been trying to add a text vertically at a existing pdf. The existing pdf is in A4 and is first converted to Letter size, then I add a single text per page.
Problem is I think Im having double text per page at different positions instead of only 1 text per page.
using (PdfReader pdfr = new PdfReader(input))
{
using (Document doc = new Document(PageSize.LETTER))
{
Document.Compress = true;
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(output, FileMode.Create));
doc.Open();
PdfPTable table;
PdfPCell cell;
Paragraph paragraph;
PdfContentByte cb = writer.DirectContent;
PdfImportedPage page;
for (int i = 1; i < pdfr.NumberOfPages + 1; i++)
{
page = writer.GetImportedPage(pdfr, i);
cb.AddTemplate(page, PageSize.LETTER.Width / pdfr.GetPageSize(i).Width, 0, 0, PageSize.LETTER.Height / pdfr.GetPageSize(i).Height, 0, 0);
table = new PdfPTable(1);
table.TotalWidth = 20;
paragraph = new Paragraph("helloworld");
cell = new PdfPCell(paragraph);
cell.Rotation = 90;
cell.BorderWidth = 10;
table.AddCell(cell);
table.WriteSelectedRows(0, -1, 300f, 200f, writer.DirectContent);
doc.Add(table);
doc.NewPage();
}
doc.Close();
doc.Dispose();
}
pdfr.Dispose();
}
For some reason another table at the top most is being generated.
you must use PdfPageEventHelper. and implement this methode public override void OnEndPage(PdfWriter writer, Document document)
I have created pdf file with itextsharp and I create Header ok but when I create table with two column. I don't have spacing from Header to my two column
The code
PdfPTable table1 = new PdfPTable(2);
table1.DefaultCell.Border = Rectangle.NO_BORDER;
table1.WidthPercentage = 100;
PdfPCell cell11 = new PdfPCell();
Paragraph UniName = new Paragraph(#"TRƯỜNG ĐẠI HỌC CÔNG NGHỆ ĐỒNG NAI", fontBold);
UniName.Alignment = Element.ALIGN_CENTER;
Paragraph paragraph = new Paragraph(#"PHÒNG ĐÀO TẠO", times);
paragraph.Alignment = Element.ALIGN_CENTER;
cell11.AddElement(UniName);
cell11.AddElement(paragraph);
cell11.BorderColor = BaseColor.WHITE;
PdfPCell cell12 = new PdfPCell();
Paragraph QH1 = new Paragraph(#"CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM", fontBold);
QH1.Alignment = Element.ALIGN_CENTER;
Paragraph QH = new Paragraph(#"Độc lập - Tự do - Hạnh phúc", fontBold);
QH.Alignment = Element.ALIGN_CENTER;
Paragraph Symbol = new Paragraph(#"----------oOo----------", fontBold);
Symbol.Alignment = Element.ALIGN_CENTER;
cell12.AddElement(QH1);
cell12.AddElement(QH);
cell12.AddElement(Symbol);
cell12.BorderColor = BaseColor.WHITE;
table1.AddCell(cell11);
table1.AddCell(cell12);
Paragraph TitleReport = new Paragraph(#"TỔNG HỢP COI CHẤM THI", titleFont);
TitleReport.Alignment = Element.ALIGN_CENTER;
Paragraph Info = new Paragraph(string.Format(#"Từ ngày: {0} đến ngày: {1} Đơn vị: {2}", DateTime.Now.AddDays(-2).ToString("dd/MM/yyyy"), DateTime.Now.ToString("dd/MM/yyyy"), "Trung tâm quản lý chất lượng"), normalFont);
Info.Alignment = Element.ALIGN_LEFT;
Info.SpacingBefore = 20;
Info.SpacingAfter = 200;
PdfContentByte canvas = writer.DirectContent;
ColumnText ct = new ColumnText(canvas);
int side_of_the_page = 0;
ct.SetSimpleColumn(COLUMNS[side_of_the_page]);
int paragraphs = 0;
while (paragraphs < 28)
{
PdfPTable table = new PdfPTable(5);
table.AddCell("STT");
table.AddCell("Số Phách");
table.AddCell("Điểm bằng số");
table.AddCell("Điểm bằng chữ");
table.AddCell("Ghi chú");
for (int i = 0; i < 33; i++)
{
table.AddCell((i + 1).ToString());
table.AddCell("209292");
table.AddCell("4");
table.AddCell("Điểm bằng chữ");
table.AddCell("");
++paragraphs;
}
table.HeaderRows = 1;
//table.LockedWidth = true;
ct.AddElement(table);
//ct.AddElement(new Paragraph(String.Format("Paragraph {0}: {1}", , TEXT)));
while (ColumnText.HasMoreText(ct.Go()))
{
if (side_of_the_page == 0)
{
side_of_the_page = 1;
canvas.MoveTo(297.5f, 36);
canvas.LineTo(297.5f, 806);
canvas.Stroke();
}
else
{
side_of_the_page = 0;
doc.NewPage();
}
ct.SetSimpleColumn(COLUMNS[side_of_the_page]);
}
}
doc.Add(table1);
doc.Add(TitleReport);
doc.Add(Info);
(Also here)
The cause of the issue is that you mix automatic layout by iText (when you add the document header and title using doc.Add) and manual layout (when you add the content using a ColumnText).
The automatic layout by iText does not take any content added by manual layout into account. Thus, you have to take the content added via automatic layout into account for your manual layout (probably it would even be easier to use manual layout for everything).
Furthermore it is a bit surprising that you add the document title after all the content. Given enough content this pushes your title onto a page beyond the first!
And your while (paragraphs < 28) does not make any sense as in the first run through the while body you immediately push that variable beyond 28 in the inner loop for (int i = 0; i < 33; i++) { ...; ++paragraphs; }.
As in your code you add the header (table1, TitleReport, Info) only once, I assume you want to use this header on the first page only.
I changed your code by:
adding the header to the Document first,
requesting the current y position from the PdfWriter,
float afterHeaderY = writer.GetVerticalPosition(true);
assuming the PdfWriter being named writer,
using this y position as the top y coordinate of the columns and the center line on the first page reverting to the hard coded 806 on later pages, and
removing the while loop and code in comments.
The new code:
PdfPTable table1 = new PdfPTable(2);
table1.DefaultCell.Border = Rectangle.NO_BORDER;
table1.WidthPercentage = 100;
PdfPCell cell11 = new PdfPCell();
Paragraph UniName = new Paragraph(#"TRƯỜNG ĐẠI HỌC CÔNG NGHỆ ĐỒNG NAI", fontBold);
UniName.Alignment = Element.ALIGN_CENTER;
Paragraph paragraph = new Paragraph(#"PHÒNG ĐÀO TẠO", times);
paragraph.Alignment = Element.ALIGN_CENTER;
cell11.AddElement(UniName);
cell11.AddElement(paragraph);
cell11.BorderColor = BaseColor.WHITE;
PdfPCell cell12 = new PdfPCell();
Paragraph QH1 = new Paragraph(#"CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM", fontBold);
QH1.Alignment = Element.ALIGN_CENTER;
Paragraph QH = new Paragraph(#"Độc lập - Tự do - Hạnh phúc", fontBold);
QH.Alignment = Element.ALIGN_CENTER;
Paragraph Symbol = new Paragraph(#"----------oOo----------", fontBold);
Symbol.Alignment = Element.ALIGN_CENTER;
cell12.AddElement(QH1);
cell12.AddElement(QH);
cell12.AddElement(Symbol);
cell12.BorderColor = BaseColor.WHITE;
table1.AddCell(cell11);
table1.AddCell(cell12);
Paragraph TitleReport = new Paragraph(#"TỔNG HỢP COI CHẤM THI", titleFont);
TitleReport.Alignment = Element.ALIGN_CENTER;
Paragraph Info = new Paragraph(string.Format(#"Từ ngày: {0} đến ngày: {1} Đơn vị: {2}", DateTime.Now.AddDays(-2).ToString("dd/MM/yyyy"), DateTime.Now.ToString("dd/MM/yyyy"), "Trung tâm quản lý chất lượng"), normalFont);
Info.Alignment = Element.ALIGN_LEFT;
Info.SpacingBefore = 20;
Info.SpacingAfter = 200;
doc.Add(table1);
doc.Add(TitleReport);
doc.Add(Info);
float afterHeaderY = writer.GetVerticalPosition(true);
Rectangle[] COLUMNS = new Rectangle[] {
new Rectangle(36, 36, 290, afterHeaderY),
new Rectangle(305, 36, 559, afterHeaderY)
};
PdfContentByte canvas = writer.DirectContent;
ColumnText ct = new ColumnText(canvas);
int side_of_the_page = 0;
ct.SetSimpleColumn(COLUMNS[side_of_the_page]);
PdfPTable table = new PdfPTable(5);
table.AddCell("STT");
table.AddCell("Số Phách");
table.AddCell("Điểm bằng số");
table.AddCell("Điểm bằng chữ");
table.AddCell("Ghi chú");
for (int i = 0; i < 33; i++)
{
table.AddCell((i + 1).ToString());
table.AddCell("209292");
table.AddCell("4");
table.AddCell("Điểm bằng chữ");
table.AddCell("");
}
table.HeaderRows = 1;
ct.AddElement(table);
while (ColumnText.HasMoreText(ct.Go()))
{
if (side_of_the_page == 0)
{
side_of_the_page = 1;
canvas.MoveTo(297.5f, 36);
canvas.LineTo(297.5f, afterHeaderY);
canvas.Stroke();
}
else
{
side_of_the_page = 0;
doc.NewPage();
COLUMNS = new Rectangle[] {
new Rectangle(36, 36, 290, 806),
new Rectangle(305, 36, 559, 806)
};
afterHeaderY = 806;
}
ct.SetSimpleColumn(COLUMNS[side_of_the_page]);
}
The result:
The big gap between header and content is due to your setting
Info.SpacingAfter = 200;
If you don't want that gap, reduce the value accordingly.
I want to draw a schedule, based on a table (including borders), where some of the cells are (partly) filled with a color. This color is based on PdfTemplate which is added as an image to the cell.
I've create a test project for it, and attached placed the output at: PDF output
In the example, I expect it to draw the filled line, everytime 2 blocks larger. As you can see, it is a bit more than the 2 blocks.
The template I create, should be the exact the size of the table cells. So I don't understand, why it keeps getting bigger every iteration.
Any ideas how to fix this?
public Test()
{
int cellWidth = 23;
int usernameCellWith = 86;
float[] scheduleTableColumnWidths = new float[33];
scheduleTableColumnWidths[0] = usernameCellWith;
for (int i = 1; i <= 32; i++)
scheduleTableColumnWidths[i] = cellWidth;
using (MemoryStream stream = new MemoryStream())
{
Rectangle rect = PageSize.GetRectangle("A4");
rect = new Rectangle(rect.Height, rect.Width, 90);
using (Document document = new Document(rect, 10f, 10f, 10f, 10f))
{
PdfWriter writer = PdfWriter.GetInstance(document, stream);
if (!document.IsOpen())
{
document.NewPage();
document.Open();
}
PdfPTable containerTable = new PdfPTable(1);
containerTable.DefaultCell.Border = Rectangle.NO_BORDER;
containerTable.WidthPercentage = 100;
PdfPTable scheduleTable = new PdfPTable(scheduleTableColumnWidths);
for (int iRow = 0; iRow <= 23; iRow++)
{
PdfPCell usernameCell = new PdfPCell(new Phrase("user "+ iRow));
usernameCell.FixedHeight = cellWidth;
scheduleTable.AddCell(usernameCell);
for (int iColumn = 1; iColumn <= 32; iColumn++)
{
PdfPCell cell = new PdfPCell();
cell.FixedHeight = cellWidth;
if (iColumn == 1 && iRow % 2 == 0)
{
float width = (float)(iRow + 1) * cellWidth;
PdfTemplate template = writer.DirectContent.CreateTemplate(width, cellWidth);
template.SetColorFill(new BaseColor(System.Drawing.ColorTranslator.FromHtml("#255C8A")));
template.Rectangle(0, 0, width, cellWidth);
template.Fill();
cell = new PdfPCell(Image.GetInstance(template));
}
scheduleTable.AddCell(cell);
}
scheduleTable.CompleteRow();
}
containerTable.AddCell(scheduleTable);
containerTable.CompleteRow();
document.Add(containerTable);
document.CloseDocument();
}
}
}
Do you absolutely need to use a PdfTemplate? Unless you've just posted a simplified version of your code it is screaming to use a colspan instead and then iText will just calculate everything for you.
Below is a modified version of what you posted. I moved some of your "magic numbers" to variables just to help my own mental process. They might not be named ideally but they do the job. Also, when working in a double for loop I recommend always looping over rows and columns and then performing logic. Your code loops over rows, does some logic for a "first cell" and then loops over a subset of the columns and performs more logic. Although absolutely 100% valid I personally find it confusing, especially when having to jump between 1 and 0 as a starting value.
Also, also, I very strongly recommend avoiding CompleteRow(). It exists to solve a certain problem but it also literally means "my logic above might be wrong so iText, could you just fudge the numbers for me?"
I commented most of what I changed so hopefully this is helpful.
public void Test() {
int cellWidth = 23;
int usernameCellWith = 86;
int maxNumberOfColumns = 32;
int maxNumberOfRows = 24;
float[] scheduleTableColumnWidths = new float[maxNumberOfColumns];
scheduleTableColumnWidths[0] = usernameCellWith;
for (int i = 1; i < maxNumberOfColumns; i++)
scheduleTableColumnWidths[i] = cellWidth;
using (MemoryStream stream = new MemoryStream()) {
iTextSharp.text.Rectangle rect = PageSize.GetRectangle("A4");
rect = new iTextSharp.text.Rectangle(rect.Height, rect.Width, 90);
using (Document document = new Document(rect, 10f, 10f, 10f, 10f)) {
PdfWriter writer = PdfWriter.GetInstance(document, stream);
//Unless this code is just a sample, a new document is never open and NewPage() is implied so these four lines could just be document.Open();
if (!document.IsOpen()) {
document.NewPage();
document.Open();
}
PdfPTable containerTable = new PdfPTable(1);
containerTable.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER;
containerTable.WidthPercentage = 100;
PdfPTable scheduleTable = new PdfPTable(scheduleTableColumnWidths);
//Loop through each row
for (int iRow = 0; iRow < maxNumberOfRows; iRow++) {
//Loop through each column
for (int iColumn = 0; iColumn < maxNumberOfColumns; iColumn++) {
//Placeholder variable that will be instantiated within the if statements below
PdfPCell cell;
//On the first column (of every row)
if (0 == iColumn) {
cell = new PdfPCell(new Phrase("user " + iRow));
//On the second column of every other row starting with the first (zeroth) row
} else if ((iColumn == 1) && (iRow % 2 == 0)) {
cell = new PdfPCell();
//Have the cell span based on the current row number
cell.Colspan = iRow + 1;
//Set the color
cell.BackgroundColor = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#255C8A"));
//Tell the inner for loop that we've accounted for some cells already
iColumn += iRow;
//Every other cell
} else {
cell = new PdfPCell();
}
//This is weird
cell.FixedHeight = cellWidth;
//Regardless of the above, add a cell
scheduleTable.AddCell(cell);
}
}
containerTable.AddCell(scheduleTable);
document.Add(containerTable);
document.CloseDocument();
}
}
}
I am creating a PdfTable from iTextSharp but the pdf containing this table does not allow editing in its cells.
How can I make sure that the cell contents are editable in resulting pdf?
iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(columnsToAdd);
table.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
Font headerFont = new Font(Font.HELVETICA, 8f, Font.BOLD, Color.BLACK);
Font bodyFont = new Font(Font.HELVETICA, 6f, Font.NORMAL, Color.BLACK);
PdfPCell cEmpId = new PdfPCell(new Phrase("Emp ID", headerFont));
PdfPCell cEmpAge = new PdfPCell(new Phrase("Emp Age", headerFont));
table.AddCell(cEmpId);
table.AddCell(cEmpAge);
foreach(Child child in childData)
{
PdfPCell cellEmpID = new PdfPCell {FixedHeight = 10f};
cellEmpID.Phrase = (new Phrase(child.Emp_ID.ToString(CultureInfo.InvariantCulture),
bodyFont));
PdfPCell cellEmpAge = new PdfPCell {Phrase = (new Phrase(child.Emp_Age, bodyFont))};
table.AddCell(cellEmpID);
table.AddCell(cellEmpAge);
}
EDIT 1:
Based on Chris's answer, I am going to try out the following code, but not sure at this time.
//WITHIN THE LOOP IN MY CODE ABOVE ADD THESE LINES FOR EVERY PDF CELL
//Create our textfield, the rectangle that we're passing in is ignored and doesn't matter
var tfEmpID = new TextField(writer, new iTextSharp.text.Rectangle(0, 0), child.Emp_ID);
//Set the cell event to our custom IPdfPCellEvent implementation
cellEmpID.CellEvent = new ChildFieldEvent(root, tfEmpID.GetTextField(), 1);
//THEN OUTSIDE THE LOOP
//IMPORTANT! Add the root annotation to the writer which also adds all of the child annotations
writer.AddAnnotation(root);
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;