PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Incorrect handling of Rotate()
https://forum.pdfsharp.net/viewtopic.php?f=3&t=734
Page 1 of 1

Author:  simbolo [ Tue May 19, 2009 4:29 am ]
Post subject:  Incorrect handling of Rotate()

Bug raised, also discussed by another user at http://forum.pdfsharp.net/viewtopic.php?t=610&highlight=rotate&mforum=pdfsharp.

Scenario:

I have a Portrait PDF, with either no Rotation value set, or it is set to 0.

I rotate by 90 degrees, giving me a Rotation from 0 to 90, the content is 90 degrees to the right, but the page is still portrait (wrong).

I rotate the result by another 90, a rotation from 90 to 180. Now the content is upside down in portrait (correct).

I rotate the result by another 90, a rotation from 180 to 270. Now the content is on its side in landscape (correct).

I rotate the result by another 90, a rotation from 270 to 0. Now the content is standing in portrait (correct).

I rotate the result by another by 90 degrees, giving me a Rotation from 0 to 90, the content is 90 degrees to the right, but the page is still portrait (wrong).

This sequence can be reversed if I make the 0>90 manually landscape, thus making all the subsequent rotations wrong way round (with content clipped of the side of the page).

I have tried when going back to zero, to subtract the existing rotation, i.e., rather than jump from 270 to 0, rotate by -270 to rotate back anti-clockwise, but this has no effect.

Its worth noting that the content is rotated correctly each time, only the page orientation is coming up wrong (at least when loaded back into Adobe Reader).

Any thoughts?

Author:  flmbray [ Fri Mar 09, 2012 2:34 am ]
Post subject:  Re: Incorrect handling of Rotate()

Not sure if you ever found a solution for this, or if perhaps it has been corrected in a more recent version (it also seems to exist in the version that I am running, file Version 1.31.1789.0)... I seem to have found a work-around. It is only slightly tested, but seems to work for me with initial testing... It's as if the page orientation doesn't get set correctly when the rotation is 0 or 180. Here's the code I use:

Code:
for (int i = 0; i < doc.PageCount; i++)
{
   var cr = doc.Pages[i].Rotate;
   doc.Pages[i].Rotate = (cr + r) % 360;
   switch (doc.Pages[i].Rotate)
   {
      case 90:
      case 270:
         break;
      case 0:
      case 180:
         doc.Pages[i].Orientation = doc.Pages[i].Orientation == PdfSharp.PageOrientation.Portrait ? PdfSharp.PageOrientation.Landscape : PdfSharp.PageOrientation.Portrait;
         break;
   }
}

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/