title: Itextsharp: Adjust 2 elements on exactly one page
body: <p>So, I'm having this problem using C# (.NET 4.0 + WinForms) and iTextSharp 5.1.2.</p>
  
  <p>I have some scanned images stored on a DB and need to build on the fly PDF with those images. Some files have just one page and other ones hundreds. That is working just fine using:</p>
  
  <pre><code>    foreach (var page in pages)
      {
          Image pageImage = Image.GetInstance(page.Image);
          pageImage.ScaleToFit(document.PageSize.Width,document.PageSize.Height);
          pageImage.Alignment = Image.ALIGN_TOP | Image.ALIGN_CENTER;
          document.Add(pageImage);
          document.NewPage();
          //...
      }
  </code></pre>
  
  <p>The problem is:</p>
  
  <p>I need to add an small table at the bottom of the last page.</p>
  
  <p>I try:</p>
  
  <pre><code>    foreach (var page in pages)
      {
          Image pageImage = Image.GetInstance(page.Image);
          pageImage.ScaleToFit(document.PageSize.Width,document.PageSize.Height);
          pageImage.Alignment = Image.ALIGN_TOP | Image.ALIGN_CENTER;
          document.Add(pageImage);
          document.NewPage();
          //...
      }
      Table t = new table....
      document.Add(t);
  </code></pre>
  
  <p>The table is successfully added but IF the size of the image fits the page size of the document then the table is added on the next page.</p>
  
  <p>I need to resize the last image of the document (if it has multiple ones, or the first if has only 1) in order to put the table directly on that page (with the image) and that both ocuppy just one page. </p>
  
  <p>I try to scale the image by percent BUT given that the image size of the image that'll be on the last page is unknow and that it must FILL the biggest portion of the page I need to do that dinamically.</p>
  
  <p>Any idea?</p>