title: center image in pdf using itextsharp
body: <p>What I'm trying to do here is to add an image to a blank pdf. So far I've done it, but I want the image to be centered. How can I do this? </p>
  
  <p>Here is my C# code:</p>
  
  <pre><code>using (MemoryStream ms = new MemoryStream())
  {
      Document doc = new Document(PageSize.A4);
      PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(System.IO.Path.Combine(filepath, strFilename), FileMode.Create));
      doc.AddTitle("Document Title");
      doc.Open();
      iTextSharp.text.Image image1 = iTextSharp.text.Image.GetInstance(@"C:\Users\Desktop\Winniethepooh.png");
      image1.Alignment = iTextSharp.text.Image.ALIGN_CENTER;
      if (image1.Height &gt; image1.Width)
      {
          //Maximum height is 800 pixels.
          float percentage = 0.0f;
          percentage = 700 / image1.Height;
          image1.ScalePercent(percentage * 100);
      }
      else
      {
          //Maximum width is 600 pixels.
          float percentage = 0.0f;
          percentage = 540 / image1.Width;
          image1.ScalePercent(percentage * 100);
      }
      //image1.Alignment = iTextSharp.text.Image.ALIGN_CENTER;
      doc.Add(image1);
      doc.Close();
  }
  </code></pre>
  
  <p>And this is the output:</p>
  
  <p><a href="https://drive.google.com/open?id=0BzaejXGgqBOAMzd0UlY2QWFXNms" rel="nofollow">https://drive.google.com/open?id=0BzaejXGgqBOAMzd0UlY2QWFXNms</a></p>
  
  <p>What I want is that the image is centered on the page. Currently the image is on the top of the page. </p>
  
  <p>I even set the image alignment, but why doesn't it center the image on the page?</p>