iTextSharp: table in landscape

匆匆过客 提交于 2019-11-30 18:05:11

问题


I'm using iTextSharp to generate a large document. In this document I want some specific pages in landscape. All the rest is portrait. Does anyone know how I can do this? Starting a new document is not an option.

Thanks!


回答1:


You can set the document size and it will affect the next pages. Some snippets:

Set up your document somewhere (you know that already):

  var document = new Document();
  PdfWriter pdfWriter = PdfWriter.GetInstance(
    document, new FileStream(destinationFile, FileMode.Create)
  );
  pdfWriter.SetFullCompression();
  pdfWriter.StrictImageSequence = true;
  pdfWriter.SetLinearPageMode();           

Now loop over your pages (you probably do that as well already) and decide what page size you want per page:

 for (int pageIndex = 1; pageIndex <= pageCount; pageIndex++) {
    // Define the page size here, _before_ you start the page.
    // You can easily switch from landscape to portrait to whatever
    document.SetPageSize(new Rectangle(600, 800));          

    if (document.IsOpen()) {
      document.NewPage();
    } else {
      document.Open();
    }
  }


来源:https://stackoverflow.com/questions/2019246/itextsharp-table-in-landscape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!