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

Pdfs with rotated pages not working properly
https://forum.pdfsharp.net/viewtopic.php?f=2&t=4152
Page 1 of 1

Author:  wiliek [ Sat Jul 04, 2020 3:07 am ]
Post subject:  Pdfs with rotated pages not working properly

I have a document assembled from other pdfs. While all the pages are in portrait orientation looking at them in code reveals that some are in landscape orientation and have a rotation of 90 or 270.

When I try to add any images or text using xgraphics the items are added vertically. I can see that the page and media box have incorrect coordinates reverse the page height and width. I don't know why it rotates the image or text + or - 90 degrees though.

I've tried changing the page orientation to portrait but that doesn't work. I tried setting rotate to 0 but that sets the page back or landscape.

I also tried to transform the xgraphics using

Code:
gfx.RotateAtTransform(90, new XPoint( page.Height/2, page.Width/2));


That works partially to rotate the text or graphics but the location is off.

I also tried
Code:
 gfx.RotateTransform(90);


but then nothing is written on the page.

I don't really know what the rotateTransform or the rotateAtTransform functions are doing.


How do I get images and text to write with the correct locations when the page has a rotation of 90 or 270 and orientation says it is Landscape even though the page is being displayed as portrait?

Author:  TH-Soft [ Mon Jul 06, 2020 7:54 am ]
Post subject:  Re: Pdfs with rotated pages not working properly

There is a known problem with rotation in version 1.50.

Maybe this post can help you:
viewtopic.php?p=11548#p11548

Workaround:
Code:
page.Orientation = PageOrientation.Portrait;


There are several problems with earlier versions (1.32 and older).

Author:  wiliek [ Thu Sep 03, 2020 9:10 pm ]
Post subject:  Re: Pdfs with rotated pages not working properly

TH-Soft wrote:
There is a known problem with rotation in version 1.50.

Maybe this post can help you:
viewtopic.php?p=11548#p11548

Workaround:
Code:
page.Orientation = PageOrientation.Portrait;


There are several problems with earlier versions (1.32 and older).


That didn't work. I tried manipulating page properties before initializing the XGraphics object but it just didn't work.

Had to rotate the Xgraphics object.
Code:
gfx.RotateAtTransform(90, new XPoint(page.Width / 2, page.Height / 2));

This resulted in the right orientation but coordinates being off because the center point in landscape and portrait are different. Figure out the difference between the two center points and shift the xgraphics accordingly. I think a better solution might be to move the graphics object from top left to bottom left then apply the rotate but I'm not interested in trying it out.

Author:  TH-Soft [ Fri Sep 04, 2020 6:36 am ]
Post subject:  Re: Pdfs with rotated pages not working properly

@All:
More details here:
viewtopic.php?f=2&t=4146&p=12919#p12919

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