title: Using iTextSharp PdfStamper to overlay an image on existing PDF
body: <p>I am able to overlay an image onto an existing PDF document using the PDFStamper and the PdfContentByte content.AddImage method.</p>
  
  <p>My problem comes up when the existing document already has an image overlayed on top. You can actually see the top edge of the small image I am trying to overlay. It is clearly hidden beneath the existing image overlay.</p>
  
  <p>I am having issues trying to get my overlayed image to show up <em>on top</em> of the existing image overlay.</p>
  
  <p>My code:</p>
  
  <pre><code>System.Drawing.Image bitmap
  
  PdfReader pdfReader = new PdfReader(pathToOriginalPdf);
  PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(pathToTimestampedPdf, FileMode.Create, FileAccess.Write, FileShare.None));
  
  MemoryStream imageStream = new MemoryStream();
  bitmap.Save(imageStream, ImageFormat.Bmp);
  byte[] bitmapBytes = imageStream.ToArray();
  
  iTextSharp.text.Image image = Image.GetInstance(bitmapBytes);
  
  PdfContentByte underContent;
  
  try
  {
      underContent = pdfStamper.GetOverContent(1);
      underContent.AddImage(image);
  }
  </code></pre>
  
  <p>I need a way to either flatten the existing image overlay onto the PDF content or set the z-order such that my newly added overlay can sit on top.</p>
  
  <p>For some reason the PdfStamper is choosing to place the new image below the existing one.</p>
  
  <p>Thanks in advance.</p>