title: How to get a landscape orientation for only some pages while converting html to pdf in itext 7?
body: <p>I convert HTML to PDF using <strong>iText7</strong> with the <code>convertToPDF()</code> method of pdfHTML. I would like to change the page orientation for a few specific pages in my PDF document. The content of these pages is dynamic, and we cannot guess how many pages that should be in landscape (i.e. content of dynamic table could take more than one page)</p>
  <p>Current situation: I create a custom worker (implements <strong>ITagWorker</strong>) which landscape the page that following the tag <code>&lt;landscape/&gt;</code></p>
  <pre><code>public byte[] generatePDF(String html) {
      ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
      PdfWriter pdfWriter = new PdfWriter(byteArrayOutputStream);
      PdfDocument pdfDocument = new PdfDocument(pdfWriter);
      try {
  
          ConverterProperties properties = new ConverterProperties();
  
          properties.setTagWorkerFactory(
                  new DefaultTagWorkerFactory() {
                      @Override
                      public ITagWorker getCustomTagWorker(
                              IElementNode tag, ProcessorContext context) {
                          if (&quot;landscape&quot;.equalsIgnoreCase(tag.name())) {
                              return new LandscapeDivTagWorker();
                          }
                          return null;
                      }
                  } );
  
          MediaDeviceDescription mediaDeviceDescription = new MediaDeviceDescription(MediaType.PRINT);
          properties.setMediaDeviceDescription(mediaDeviceDescription);
  
          HtmlConverter.convertToPdf(html, pdfDocument, properties);
      } catch (IOException e) {
          e.printStackTrace();
      }
      pdfDocument.close();
      return byteArrayOutputStream.toByteArray();
  }
  </code></pre>
  <p>The custom worker :</p>
  <pre><code>public class LandscapeDivTagWorker implements ITagWorker {
  
      @Override
      public void processEnd(IElementNode element, ProcessorContext context) {
      }
  
      @Override
      public boolean processContent(String content, ProcessorContext context) {
          return false;
      }
  
      @Override
      public boolean processTagChild(ITagWorker childTagWorker, ProcessorContext context) {
          return false;
      }
  
      @Override
      public IPropertyContainer getElementResult() {
          return new AreaBreak(new PageSize(PageSize.A4).rotate());
      }
  }
  </code></pre>
  <p>Is there a way to define all the content that should be displayed in landscape?</p>
  <p>Something like:</p>
  <pre><code>&lt;p&gt;Display in portrait&lt;/p&gt;
  &lt;landscape&gt;
  &lt;div&gt;
  &lt;p&gt;display in landscape&lt;/p&gt;
  …
  &lt;table&gt;
  ..
  &lt;/table&gt;
  &lt;/div&gt;
  &lt;/landscape&gt;
  </code></pre>
  <p>or with a CSS class :</p>
  <pre><code>&lt;p&gt;Display in portrait&lt;/p&gt;
  &lt;div class=&quot;landscape&quot;&gt;
  &lt;p&gt;display in landscape&lt;/p&gt;
  …
  &lt;table&gt;
  ..
  &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  <p>Result =&gt; 1 page in portrait and other page<strong>s</strong> in <strong>landscape</strong> (All the div content should be in landscape)</p>
  <p>PS: I follow this hint <a href="https://stackoverflow.com/questions/54215613/change-page-orientation-for-only-some-pages-in-the-resulting-pdf-created-out-of/54232433">Change page orientation for only some pages in the resulting PDF (created out of html)</a> by using a custom <strong>CssApplierFactory</strong> but the result was the same =&gt; just the first page where the landscape class is used was in landscape and the other content of the table was in portrait</p>