iTextSharp: table in landscape

前端 未结 1 1950
逝去的感伤
逝去的感伤 2021-01-06 18:15

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? S

1条回答
  •  花落未央
    2021-01-06 18:42

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

    0 讨论(0)
提交回复
热议问题