title: Adding an image to a PDF using iTextSharp and scale it properly
body: <p>here's my code. It correctly adds the pictures I want and everything works <strong>except</strong> that the images are using their native resolution, so if the image is big it's being cropped to fit the page.</p>
  
  <p>Is there some way to have the picture use like a Zoom feature to stretch to fit, but also maintain the aspect ratio? There has to be something I'm missing there. :P</p>
  
  <p>Here's a picture to illustrate the problem:
  <img src="https://i.stack.imgur.com/bHS6p.png" alt="alt text"></p>
  
  <pre><code>using System;
  using System.IO;
  using iTextSharp.text;
  using iTextSharp.text.pdf;
  using System.Drawing;
  using System.Collections.Generic;
  
  namespace WinformsPlayground
  {
      public class PDFWrapper
      {
          public void CreatePDF(List&lt;System.Drawing.Image&gt; images)
          {
              if (images.Count &gt;= 1)
              {
                  Document document = new Document(PageSize.LETTER);
                  try
                  {
  
                      // step 2:
                      // we create a writer that listens to the document
                      // and directs a PDF-stream to a file
  
                      PdfWriter.GetInstance(document, new FileStream("Chap0101.pdf", FileMode.Create));
  
                      // step 3: we open the document
                      document.Open();
  
                      foreach (var image in images)
                      {
                          iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(image, System.Drawing.Imaging.ImageFormat.Jpeg);
                          document.Add(pic);
                          document.NewPage();
                      }
                  }
                  catch (DocumentException de)
                  {
                      Console.Error.WriteLine(de.Message);
                  }
                  catch (IOException ioe)
                  {
                      Console.Error.WriteLine(ioe.Message);
                  }
  
                  // step 5: we close the document
                  document.Close();
              }
          }
      }
  }
  </code></pre>