iTextsharp景观文件

我正在尝试使用iTextSharp创建Landscape PDF,但它仍然显示肖像。 我正在使用以下代码旋转:

Document document = new Document(PageSize.A4, 0, 0, 150, 20); FileStream msReport = new FileStream(Server.MapPath("~/PDFS/") + "Sample1.pdf", FileMode.Create); try { // creation of the different writers PdfWriter writer = PdfWriter.GetInstance(document, msReport); document.Open(); PdfPTable PdfTable = new PdfPTable(1); PdfTable.SpacingBefore = 30f; PdfPCell PdfPCell = null; Font fontCategoryheader = new Font(Font.HELVETICA, 10f, Font.BOLD, Color.BLACK); for (int i = 0; i < 20; i++) { PdfPCell = new PdfPCell(new Phrase(new Chunk("Sales Manager: ", fontCategoryheader))); PdfPCell.BorderWidth = 0; PdfPCell.HorizontalAlignment = Element.ALIGN_LEFT; if (i % 2 == 0) PdfPCell.BackgroundColor = Color.LIGHT_GRAY; PdfPCell.PaddingBottom = 5f; PdfPCell.PaddingLeft = 2f; PdfPCell.PaddingTop = 4f; PdfPCell.PaddingRight = 4f; PdfTable.AddCell(PdfPCell); } document.Add(PdfTable); document.NewPage(); } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } finally { // we close the document document.Close(); } 

请建议解决方案。

谢谢。

试试这个

 Document Doc = new Document(new Rectangle(288f, 144f), 10, 10, 10, 10); Doc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate()); 

您可能还需要将表扩展到最大宽度。

 var _pdf_table = new PdfPTable(2); // table with two columns PdfPCell hc = new PdfPCell(); _pdf_table.WidthPercentage = 100; //table width to 100per _pdf_table.SetTotalWidth(new float[] { 25, iTextSharp.text.PageSize.A4.Rotate().Width - 25 });// width of each column 

问候。

无需初始化文档并重置页面大小……

 Document doc = new Document(iTextSharp.text.PageSize.A4.Rotate(), 10, 10, 10, 10); 

……会做的。

(4.1.6.0)