title: iTextSharp: Stamp rotated/placed incorrectly
body: <p>I am implementing another app that makes use of stamping using iTextsharp 7. I've had this issue on multiple instances. My stamping code resembles the following:</p>
  
  <pre><code> public Stamper(PdfDocument _doc, Rectangle _rect)
      {
          doc = _doc;
          Location = _rect;
      }
  
      public void StampPDF()
      {
          PdfDocument srcDoc = new PdfDocument(new PdfReader(Settings.Default.DefaultAppearance.SignStamp));
          // Create FormXObject and Canvas
  
          PdfFormXObject page = srcDoc.GetFirstPage().CopyAsFormXObject(doc);
          //Extract Page Dimensions
          float xWidth = srcDoc.GetFirstPage().GetCropBox().GetWidth();
          float xHeight = srcDoc.GetFirstPage().GetCropBox().GetHeight();
          //Better safe than sorry....
          double ratio = xHeight / xWidth;
          ratio = (float)ratio;
  
          float scaledXHeight = Location.GetHeight();
          float scaledXWidth = (float)(scaledXHeight / ratio * 1.0);
  
  
  
          //Rectangle location = new Rectangle(crop.GetLeft(), crop.GetBottom(), scaledXWidth , scaledXHeight );
  
  
          PdfStampAnnotation stamp = new PdfStampAnnotation(Location).SetStampName(new PdfName(Settings.Default.DefaultAppearance.SignName+" Signature"));
          PdfCanvas canvas = new PdfCanvas(doc.GetFirstPage().NewContentStreamBefore(), doc.GetFirstPage().GetResources(), doc);
  
         // canvas.AddXObject(page,location.GetLeft(),location.GetBottom(),page.GetWidth());
          stamp.SetNormalAppearance(page.GetPdfObject());
          stamp.SetFlags(PdfAnnotation.PRINT);
          doc.GetFirstPage().AddAnnotation(stamp);
  
  
          srcDoc.Close();
  </code></pre>
  
  <p>Noting that I am merging another PDF as my stamp. Once I try to create a Rectangle to a specific slot, my stamp ends up being either OVER-STRETCHED , or ROTATED 90 degrees. I suspect that it is a consequence of the merged PDF having a rotation that is non-zero. However, even setting it's rotation to 0 doesn't fix the problem. Moreover, the issue is exacerbated if the page I am stamping on is rotated, using a reference point like the CropBox simply fails and stamps in an unintended area and orientation.</p>
  
  <p><strong>EDIT</strong>: Updated code to reflect my exact situation. The function is receiving and already existing (hardcoded) Rectangle called Location and is expected to stamp inside it while maintaining the correct proportions.</p>
  
  <p>How do you compensate for the rotation issue?</p>