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

PdfPage.Orientation in combination with Width and Height
https://forum.pdfsharp.net/viewtopic.php?f=3&t=3252
Page 1 of 1

Author:  MJLaukala [ Mon Dec 21, 2015 8:17 pm ]
Post subject:  PdfPage.Orientation in combination with Width and Height

I've forked the new GitHub repo witch I am happy that exists now.

It seems that PdfPage.Orientation is causing a bit of havoc throughout the code in relation to getting the Width and Height of the PdfPage. Currently the Width and Height properties return the rotated(rendered) width and height. The Orientation is not reset when a new rotation is applied(which doesn't fix anything). The Width and Height properties are used improperly throughout the source and the MediaBox is changed on occasion based on the value of the Orientation property. This is causing pages to be cut off when simply saving that page. The current work around is to set the Orientation property to portrait, which ensures that all properties getters return the correct value and that any value that is changed when set to landscape does not get changed(such as MediaBox). My questions are,

1: Are you accepting pull requests on GitHub?
if so,
2: What should be done about this?

I have no issue taking the time to correct the related issues with PdfPage.Orientation but before doing so, I would like a clear direction on what should be done. My personal preference is to remove PdfPage.Orientation entirely.

Author:  TH-Soft [ Mon Dec 21, 2015 9:15 pm ]
Post subject:  Re: PdfPage.Orientation in combination with Width and Height

I hope you have seen this thread and the suggested modification:
viewtopic.php?p=9587#p9587

My personal and private opinion is that a change that removes PdfPage.Orientation probably will not be merged into the master version.

Rotation and orientation are independent properties. Rotation is saved to the PDF file, orientation is internal to PDFsharp.

Author:  MJLaukala [ Mon Dec 21, 2015 11:11 pm ]
Post subject:  Re: PdfPage.Orientation in combination with Width and Height

"Rotation and orientation are independent properties." That's only partly true. The orientation is set for a PdfPage of an opened document. But it can be set afterwards witch does not immediately affect anything.

"orientation is internal to PDFsharp" Kinda true. While it does not get saved to the pdf document, it is used incorrectly to determine the dimensions of the MediaBox and other values which is the whole reason behind my post. It's breaking the way pdfs should be saved.

Commenting out those lines of code is essentially setting the orientation to PageOrientation.Portiat (the default value). While it is easier to write code using an enum over testing the rotation every time it is needed, everywhere in the code that actually uses the Orientation property seems to be incorrect. From what I can tell, after all the fixes it wont even be necessary to have. If anything, it needs to not affect other values, have a private setter and only be updated when the rotation of the page is set.

Tomorrow, I'm going to write my suggested fix in this reply and do a pull request. If they accept it, Awesome. If not, At least I'll have a proper fix until they deal with it.

Author:  MaxDna [ Tue Dec 22, 2015 3:16 pm ]
Post subject:  Re: PdfPage.Orientation in combination with Width and Height

MJLaukala wrote:
"Rotation and orientation are independent properties." That's only partly true. The orientation is set for a PdfPage of an opened document. But it can be set afterwards witch does not immediately affect anything.

"orientation is internal to PDFsharp" Kinda true. While it does not get saved to the pdf document, it is used incorrectly to determine the dimensions of the MediaBox and other values which is the whole reason behind my post. It's breaking the way pdfs should be saved.

Commenting out those lines of code is essentially setting the orientation to PageOrientation.Portiat (the default value). While it is easier to write code using an enum over testing the rotation every time it is needed, everywhere in the code that actually uses the Orientation property seems to be incorrect. From what I can tell, after all the fixes it wont even be necessary to have. If anything, it needs to not affect other values, have a private setter and only be updated when the rotation of the page is set.

Tomorrow, I'm going to write my suggested fix in this reply and do a pull request. If they accept it, Awesome. If not, At least I'll have a proper fix until they deal with it.


Please, take a look at some modification I'm using to handle portrait and landscape PDF (I've just posted the code in the forum).
http://forum.pdfsharp.net/viewtopic.php?f=3&t=3247
Now it works with portrait and Landscape (90° rotations)
It doesn't works with landscape rotated by 270°

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