Question

Hy, I want to know if it's possible to rotate a PdfPTable. I have a template pdf where I need to add a table under a specific element but I can't find a way to achieve this. I tried adding the table to a paragraph but I'm not able to rotate the paragraph. this is my code

PdfPTable table = new PdfPTable(15);
foreach(var row in Rows)
{
    PdfPCell[] cells = new PdfPCell[] { 
                    new PdfPCell(new Phrase(row.ID.ToString())) 
    //***MANY OTHER CELLS***//
    };
    PdfPRow row = new PdfPRow(cells);
    table.Rows.Add(row);
}
table.CompleteRow();
Paragraph paragraph = new Paragraph();
paragraph.Add(table);

PdfImportedPage page = writer.GetImportedPage(reader, 1);
cb.AddTemplate(page, 0,-1f,1f,0,0,reader.GetPageSizeWithRotation(1).Width);
doc.Add(paragraph);

I want to add the table under my template, I could even add the table to the template if this could be helpful. someone has some ideas? thank's

Was it helpful?

Solution

You're using PdfWriter which involves rotating the page and rotating the table you're adding on top of that page. You can avoid this problem, by adding the table using PdfStamper. In this case, you can just add the table and if the rotation setting of the page is OK, the table will automatically be rotated too, unless you use the following line:

stamper.setRotateContents(false);

By default, the extra content will have the same rotation of the page.

OTHER TIPS

Please see below to rotate your table:

Document doc = new Document(iTextSharp.text.PageSize.LETTER.Rotate(), 20, 20, 42, 35);

To rotate cell is

pdfPCell.Rotation = 90;

Hope above will help you!!!

I didn't achieve result in C# to rotate content in table by 180 degrees with

pdfPCell.Rotation = 180;  

but got with

table.DefaultCell.Rotation = 180;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top