title: How do i use iText to have a landscaped PDF on half of a A4 back to portrait and full size on A4
body: <p>I have a landscaped form lay on a top half of A4 page, I want it to be rotated  and enlarge to a portrait layout size fill up the A4 then saved before it is faxed out. Otherwise, the fax service program will fax it out with only partial info. Here is my attempt, result is the same as the input pdf. This is my first day on programming using iText, all the google not getting me what I want. Please let me know if you can help. Thanks,</p>
  
  <pre><code>public class CopeALandscapePdfFiletoPortraitPdfFile {
  //public static final String SRC = "resources/pdfs/landscapeForm.pdf";
  public static final String SRC = "resources/pdfs/potraitForm.pdf";
  public static final String DEST = "results/stamper/portraitFormAfterCopy.pdf";
  
  public static void main(String[] args) throws IOException, DocumentException
  {   
      copyPdf();
  }
  
  private static void copyPdf() throws IOException, DocumentException
  {
      Document document = new Document(PageSize.A4);
  
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST));
      document.open();
      PdfContentByte cb = writer.getDirectContent();
  
      PdfReader reader = new PdfReader(SRC);
      document.newPage();
      int n = reader.getNumberOfPages();
      PdfDictionary page;
      PdfNumber rotate;
      for (int p = 1; p &lt;= n; p++) {
          page = reader.getPageN(p);
          rotate = page.getAsNumber(PdfName.ROTATE);
  
          if (rotate == null) {
              page.put(PdfName.ROTATE, new PdfNumber(90));
          } else {
              page.put(PdfName.ROTATE, new PdfNumber((rotate.intValue() + 90) % 360));
          }
  
      } 
      PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(DEST));
      stamper.close();
  
      PdfImportedPage ipage = writer.getImportedPage(stamper.getReader(), 1);
      cb.addTemplate(ipage, 0, 0);
  
      document.close();
  }
  </code></pre>
  
  <p>}</p>