Changing Column Alignment to "RIGHT" in iTextSharp from Win Form - c#

I am trying to align one of my datagrid column of "Amount" to right side but unable to do so while trying to create PDF using itextsharp. All the columns are left aligned, some colums should be left aligned and the last column should be right aligned. Please help
Below listed is the code.
PdfPTable pdfTable = new PdfPTable(dataGridView1.ColumnCount);
pdfTable.SetWidths(new float[] { 5f, 10f, 10f, 7f, 9f });
pdfTable.DefaultCell.Padding = 3;
pdfTable.WidthPercentage = 90;
pdfTable.HorizontalAlignment = Element.ALIGN_LEFT;
pdfTable.DefaultCell.BorderWidth = 1;
foreach (DataGridViewColumn column in dataGridView1.Columns)
{
PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText, fontTitle2));
cell.BackgroundColor = new iTextSharp.text.BaseColor(240, 240, 240);
cell.HorizontalAlignment = Element.ALIGN_CENTER;
pdfTable.AddCell(cell);
}
foreach (DataGridViewRow row in dataGridView1.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
pdfTable.AddCell(new Phrase(cell.Value.ToString(), fontTitle));
}
}

Your question is strange, because you create your first row in a way that leads to assume that you already know the answer to your question.
When you create your first row, you do:
PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText, fontTitle2));
cell.BackgroundColor = new iTextSharp.text.BaseColor(240, 240, 240);
cell.HorizontalAlignment = Element.ALIGN_CENTER;
pdfTable.AddCell(cell);
You create a PdfPCell in text mode and you set the alignment to ALIGN_CENTER at the level of the cell. This is correct.
When you create the subsequent rows, you do:
pdfTable.AddCell(new Phrase(cell.Value.ToString(), fontTitle));
This also creates a PdfPCell in text mode (internally) and the alignment of the default cell is used. If you didn't change this alignment, the alignment is ALIGN_LEFT.
Instead of using:
pdfTable.AddCell(new Phrase(cell.Value.ToString(), fontTitle));
Why don't you use the knowledge you already had when you created the code for the first row?
PdfPCell cell = new PdfPCell(new Phrase(cell.Value.ToString(), fontTitle));
cell.HorizontalAlignment = Element.ALIGN_RIGHT;
pdfTable.AddCell(cell);
Of course: if some cells need Element.ALIGN_LEFT and other cells need Element.ALIGN_RIGHT, you'll have to add an if in your loop. That if should check if cell is the last cell in the row or not.

Related

How to make the table border length as per cell data length c#?

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();
}
}

Align text in center of cell next to image in itexsharp

Here is visual what my problem looks like.
Here is my code that produce that result.
public void intervencionHeaderLogo(string pictureURL,int width, int height)
{
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(System.Web.HttpContext.Current.Server.MapPath(pictureURL));
image.ScaleAbsolute(width, height);
image.Alignment = 2;
//Table
PdfPTable table = new PdfPTable(1);
PdfPCell cell = new PdfPCell();
BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 20, iTextSharp.text.Font.NORMAL);
Paragraph p = new Paragraph("Reporte de intervención", font);
//Cell no 1
cell = new PdfPCell();
cell.Border = 0;
cell.AddElement(p);
cell.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(cell);
//Cell no 2
cell = new PdfPCell();
cell.Border = 0;
cell.AddElement(image);
table.AddCell(cell);
//Add table to document
pdfDoc.Add(table);
}
Here is what I want to have.
Any help would be appriciated
I was able to fix it i made a mistake i create a table of 1 when i should have made it of size 2.
//Table
PdfPTable table = new PdfPTable(2);
and the i added a line break like this in the paragraph like this
Paragraph p = new Paragraph("\nReporte de intervención", font);

Formatting itextsharp table

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)

iText Sharp nested table colspan

I have a main table 'table' with 3 columns of width {50f,25f,25f}.I created 2 nested tables .
In nested table 1,
PdfPTable nested12 = new PdfPTable(1);
PdfPCell cell1 = new PdfPCell(new Phrase("cell1 of nested table1", bodyFontnormalItalic));
cell1.Border = Rectangle.BOTTOM_BORDER;
nested12.AddCell(cell1);
PdfPCell cell2 = new PdfPCell(new Phrase("cell2 of nested table1", bodyFontLight));
cell2.Border = Rectangle.BOTTOM_BORDER;
nested12.AddCell(cell2);
PdfPCell cell3 = new PdfPCell(new Phrase("cell3 of nested table1", bodyFontLight));
cell3.Border = Rectangle.BOTTOM_BORDER;
nested12.AddCell(cell3);
PdfPCell nesthousing12 = new PdfPCell(nested12);
nesthousing12.Padding = 0f;
nesthousing12.Colspan = 1;
table.AddCell(nesthousing12);
Nested table 2 is :
PdfPTable nestedTable2 = new PdfPTable(1);
PdfPCell cell4 = new PdfPCell(new Phrase("cell1 of nested table 2", bodyFontnormalItalic));
cell4.Border = Rectangle.BOTTOM_BORDER;
nestedTable2.AddCell(cell4); //here 2 cells of colspan=1 needed
PdfPCell cell5 = new PdfPCell(new Phrase("cell2 of nested table 2", bodyFontLight));
cell5.Border = Rectangle.BOTTOM_BORDER;
nestedTable2.AddCell(cell5);
PdfPCell cell6 = new PdfPCell(new Phrase("cell3 of nested table 3", bodyFontLight));
cell6.Border = Rectangle.BOTTOM_BORDER;
nestedTable2.AddCell(cell6);
PdfPCell nesthousing = new PdfPCell(nestedTable2);
nesthousing.Padding = 0f;
nesthousing.Colspan = 2;
table.AddCell(nesthousing);
For nested table 2, i used Colspan=2 . I need nestedtable2 in the bellow format. First row of nested table2 should have 2 cells.
So how can i create like this ? can you please help me.
edit:
Above Table is what the exact output i need. so i created one table with 6 columns. inner table of 3 columns for address and other details.
I am ignoring the code in your question, because I don't understand it. I only understand the image you shared and I've written some pseudo code that allows you to create a table that looks like this:
This looks more or less like the desired result, doesn't it? Now it's up to you to convert the following pseudo code to C#.
This is the code to draw the border of the main table:
public class BorderEvent implements PdfPTableEvent {
public void tableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) {
float width[] = widths[0];
float x1 = width[0];
float x2 = width[width.length - 1];
float y1 = heights[0];
float y2 = heights[heights.length - 1];
PdfContentByte cb = canvases[PdfPTable.LINECANVAS];
cb.rectangle(x1, y1, x2 - x1, y2 - y1);
cb.stroke();
}
}
This is the code that creates the full table:
public void createPdf(String dest) throws IOException, DocumentException {
Document document = new Document(PageSize.A4.rotate());
PdfWriter.getInstance(document, new FileOutputStream(dest));
document.open();
PdfPTable table = new PdfPTable(4);
table.setTableEvent(new BorderEvent());
table.setWidths(new int[]{1, 12, 8, 1});
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
// first row
PdfPCell cell = new PdfPCell(new Phrase("Main table"));
cell.setBorder(Rectangle.NO_BORDER);
cell.setColspan(4);
table.addCell(cell);
// second row
table.addCell("");
table.addCell("nested table 1");
table.addCell("nested table 2");
table.addCell("");
// third row
// third row cell 1
table.addCell("");
// third row cell 2
PdfPTable table1 = new PdfPTable(1);
table1.addCell("cell 1 of nested table 1");
table1.addCell("cell 2 of nested table 1");
table1.addCell("cell 2 of nested table 1");
table.addCell(new PdfPCell(table1));
// third row cell 3
PdfPTable table2 = new PdfPTable(2);
table2.getDefaultCell().setMinimumHeight(10);
table2.addCell("");
table2.addCell("");
cell = new PdfPCell(new Phrase("cell 2 of nested table 2"));
cell.setColspan(2);
table2.addCell(cell);
cell = new PdfPCell(new Phrase("cell 3 of nested table 2"));
cell.setColspan(2);
table2.addCell(cell);
table.addCell(new PdfPCell(table2));
// third row cell 4
table.addCell("");
// fourth row
cell = new PdfPCell();
cell.setColspan(4);
cell.setBorder(Rectangle.NO_BORDER);
cell.setMinimumHeight(16);
table.addCell(cell);
document.add(table);
document.close();
}
As you can see, the nested table 2 needs to have 2 columns so that you can have two cells in its first row. Obviously, you need to define a colspan of 2 for the two cells that are used for row 2 and 3.
You may have noticed that the pseudocode is actually working Java code. It shouldn't be a problem for you to interpret that code and to port it to C#.
Update
You seem to have a knack for making simple things look complicated. In your original drawing, you drew an extra rectangle around the desired result. In my answer, I mimicked that drawing in the NestedTables4 example and you weren't happy with the result.
Now you've simplified your drawing and I made a NestedTables5 example that is much easier to understand. The result looks like this:
In spite of the simplicity, you still make the problem sound complex. You say (and I quote): i created one table with 6 columns. inner table of 3 columns. But that doesn't make sense, does it?
If you want to create this complete structure in 1 single table, using two inner tables, you need a table with 7 colums:
The first cell has colspan 3 and contains a table with 1 column and 3 rows. The second cell has colspan 4 and contains a table with 2 columns and 3 rows. The third cell in the lower part of the table always has colspan 2.
That's elementary logic. However, why would you make a simple table like this so complex? As documented, PdfPTable was designed in such a way that you can add multiple instances of PdfPTable one after the other, without even noticing that there are different tables at play.
This is what I did in the NestedTables5 example. I created a table with 2 columns for the upper part and a table with 6 columns for the lower part:
public void createPdf(String dest) throws IOException, DocumentException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(dest));
document.open();
// Header part
PdfPTable table = new PdfPTable(2);
table.setWidths(new int[]{50, 50});
// first cell
PdfPTable table1 = new PdfPTable(1);
table1.getDefaultCell().setMinimumHeight(30);
table1.addCell("Address 1");
table1.addCell("Address 2");
table1.addCell("Address 3");
table.addCell(new PdfPCell(table1));
// second cell
PdfPTable table2 = new PdfPTable(2);
table2.addCell("Date");
table2.addCell("Place");
PdfPCell cell = new PdfPCell(new Phrase("References"));
cell.setMinimumHeight(40);
cell.setColspan(2);
table2.addCell(cell);
cell = new PdfPCell(new Phrase("destination"));
cell.setColspan(2);
table2.addCell(cell);
table.addCell(new PdfPCell(table2));
// second row
cell = new PdfPCell();
cell.setColspan(2);
cell.setMinimumHeight(16);
table.addCell(cell);
document.add(table);
// Body part
table = new PdfPTable(6);
table.setWidths(new int[]{ 1, 2, 6, 1, 2, 2 });
table.addCell("sl no");
table.addCell("qty");
table.addCell("Product");
table.addCell("units");
table.addCell("rate");
table.addCell("total");
table.setHeaderRows(1);
for (int i = 0; i < 6; ) {
table.getDefaultCell().setBorder(Rectangle.LEFT | Rectangle.RIGHT);
table.getDefaultCell().setMinimumHeight(16);
table.addCell(String.valueOf(++i));
table.addCell("");
table.addCell("");
table.addCell("");
table.addCell("");
table.addCell("");
}
table.getDefaultCell().setFixedHeight(3);
table.getDefaultCell().setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
table.addCell("");
table.addCell("");
table.addCell("");
table.addCell("");
table.addCell("");
table.addCell("");
document.add(table);
document.close();
}
That gives you the result as shown in your second drawing. See nested_tables5.pdf and compare it with what you need.
Important
It looks as if you're creating invoices with iTextSharp and that you have been trying to do so since March 28 (that's a week ago). In the future, please read the documentation first. That will save you plenty of time that you would otherwise lose in a trial-and-error process. You can download an ebook entitled ZUGFeRD: The Future of Invoicing for free, and you can even browse that book for free online: ZUGFeRD: The Future of Invoicing. It explains step by step how to create invoices such as the one shown in the figure below:
Why would you reinvent the wheel if all the examples are out there?
PdfPTable table = new PdfPTable(3);
table.AddCell(new PdfPCell(new Phrase("Sr No")) { Rowspan = 2, BackgroundColor = BaseColor.GRAY });
PdfPCell CellZero1 = table.AddCell(new PdfPCell(new Phrase("Name")) { Rowspan = 2, HorizontalAlignment = Element.ALIGN_CENTER, BackgroundColor = BaseColor.GRAY });
CellZero1.VerticalAlignment = Element.ALIGN_CENTER;
table.AddCell(new PdfPCell(new Phrase("Phone")) { Rowspan = 2, BackgroundColor = BaseColor.GRAY });
PdfPTable nestedTable = new PdfPTable(2);
PdfPCell cell1 = new PdfPCell(new Phrase("12") );
PdfPCell cell2 = new PdfPCell();
PdfPCell cell3 = new PdfPCell(new Phrase("545445444"));
nestedTable.AddCell(new PdfPCell(new Phrase("First Name")){ BackgroundColor = BaseColor.GRAY });
nestedTable.AddCell(new PdfPCell(new Phrase("Last Name")) { BackgroundColor = BaseColor.GRAY });
for (int i = 1; i < 6; i++)
{
nestedTable.AddCell(new PdfPCell(new Phrase("data" + i)) );
nestedTable.AddCell(new PdfPCell(new Phrase("last" + i)) );
}
cell2.AddElement(nestedTable);
table.AddCell(cell1);
table.AddCell(cell2);
table.AddCell(cell3);
doc.Add(table);

Hiding table border in iTextSharp

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;

Categories

Resources