title: iTextSharp. Why cell background image is rotated 90 degrees clockwise?
body: <p>I would like to have cell background using it's natural dimensions and if they don't fit cell - image should be cropped.
  One more thing that when I use pattern fill image is actually 90 degress rotated. So the <strong>main thing in this question is why pattern image is rotated after it adding</strong>
  I have googled for answer and read documentation, but can't find any explanation.
  Here is code:</p>
  
  <pre><code>Image img = Image.GetInstance("someImage.png");
  
  var cell = new PdfPCell()
  {
      BorderWidthTop = 0,
      BorderWidthBottom = 0,
      BorderWidthLeft = 0,
      BorderWidthRight = 0,
      Padding = 0,
      BackgroundColor = new BaseColor(244, 244, 244),
      BorderColor = new BaseColor(217, 217, 217),
      HorizontalAlignment = Element.ALIGN_CENTER
  };
  cell.CellEvent = new CellBackgroundEvent() {Image = img};
  table.AddCell(cell)
  ;
  </code></pre>
  
  <p>And here is event handler class:</p>
  
  <pre><code>private class CellBackgroundEvent : IPdfPCellEvent
  {
      public Image Image { get; set; }
  
      void IPdfPCellEvent.CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases)
      {
          PdfContentByte cb = canvases[PdfPTable.BACKGROUNDCANVAS];
          PdfPatternPainter patternPainter = cb.CreatePattern(position.Right - position.Left, position.Top - position.Bottom);
          patternPainter.AddImage(Image, position.Right - position.Left, 0, 0, position.Top - position.Bottom, 0, 0);
          cb.SaveState();
          cb.SetPatternFill(patternPainter);
          cb.Rectangle(position.Left, position.Bottom, position.Width, position.Height);
          cb.Fill();
          cb.RestoreState();
      }
  }
  </code></pre>
  
  <p>After execution cell background image is rotated 90 degrees clockwise, why?</p>
  
  <p>Image is: <img src="https://i.stack.imgur.com/ALxRF.png" alt="enter image description here"></p>
  
  <p>Actual result cell is: </p>
  
  <p><img src="https://i.stack.imgur.com/ADXRv.png" alt="enter image description here"></p>
  
  <p>C# iTextSharp lib version: 5.5.0.0</p>