ITextSharp: table in landscape

I use iTextSharp to create a large document. In this document, I want some specific pages to be in landscape. Everything else is a portrait. Does anyone know how I can do this? Starting a new document is not an option.

Thank!

+3
source share
1 answer

You can set the size of the document and affect the following pages. Some snippets:

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

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

Now let's move on to your pages (maybe you will do it too) and decide what page size you want on the 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();
    }
  }
+7
source

Source: https://habr.com/ru/post/1727594/


All Articles