简体   繁体   English

旋转itextsharp PdfPtable

[英]Rotating an itextsharp PdfPtable

Hy, I want to know if it's possible to rotate a PdfPTable. 嗨,我想知道是否可以旋转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. 我有一个pdf模板,我需要在特定元素下添加表格,但是我找不到实现此目的的方法。 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 谢谢

You're using PdfWriter which involves rotating the page and rotating the table you're adding on top of that page. 您正在使用PdfWriter ,它涉及旋转页面和旋转要在该页面顶部添加的表。 You can avoid this problem, by adding the table using PdfStamper . 您可以通过使用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. 默认情况下,多余的内容将具有相同的页面旋转度。

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 我没有在C#中将表中的内容旋转180度的结果

pdfPCell.Rotation = 180;  

but got with 但是得到了

table.DefaultCell.Rotation = 180;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM