title: iTextSharp how to rotate/switch page from landscape to portrait
body: <p>I'm using iTextSharp to merge multiple PDF files into a single Pdf. I found a <a href="http://khsw.blogspot.com/2006/04/merge-pdf-files-using-itextsharp.html" rel="nofollow noreferrer">code sample</a>  or <a href="http://www.codeproject.com/KB/files/SimplePdfMerger.aspx" rel="nofollow noreferrer">two</a> on the web as to how to accomplish this task.</p>
  
  <p>They all work, with no apparent issues, as I'm able to merge multiple PDF files into a single PDF. </p>
  
  <p>The issue that I do have is that I would like for all the pages to be in PORTRAIT, as some of the PDF files have pages in LANDSCAPE and I would like for them to be rotated to PORTRAIT. I do not mind that they will either be upside down or sideways, but they must all be in portrait.</p>
  
  <p>Looking at the code sections in the examples listed:</p>
  
  <pre><code>page = writer.GetImportedPage(reader, i);
  rotation = reader.GetPageRotation(i);
  </code></pre>
  
  <p>always returns the page rotation value as 0 (zero) thus the code section</p>
  
  <pre><code>if (rotation == 90 rotation == 270)
  {
      cb.AddTemplate(page, 0, -1f, 1f, 0, 0, 
                           reader.GetPageSizeWithRotation(i).Height);
  }
  </code></pre>
  
  <p>never gets executed (if that is what is supposed to do, rotating the page).</p>
  
  <p>So, based on the code in the link of the 1st code sample <code>page = writer.GetImportedPage(reader, i)</code> how would I go about to change the page layout of the <code>page</code> from Landscape to Portrait, before I add it to the new merged PDF document with <code>cb.AddTemplate...</code>?</p>
  
  <p>PS. Determining whether a page is either landscape or portrait I use the following piece of <a href="https://stackoverflow.com/questions/1905433/centering-an-pdfimportedpage-in-itextsharp">code</a> obtained from SO (adapted for the code example above):</p>
  
  <pre><code>float pageXYRatio = page.Width / page.Height;
  if (XYRatio &gt; 1f)
  {
      //page is landscape
  }
  else
  {
      //page is portrait
  }
  </code></pre>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks</p>