Closed Hacnar closed 1 year ago
I spent a bit more time debugging this, and I found that the only difference in the resulting pdf files was /MediaBox property of PdfPage, which seemed to switch width and height every time the files has been saved to disk.
I've found the source of this issue. Some PDF files have unusual setting - rotation would suggest landscape orientation, but the page dimensions suggest otherwise. When I initialize PdfPage._orientation with values in /MediaBox taken into consideration, things work fine. I suspect Adobe and other PDF viewers approach orientation similarly, because they reported Portrait when PdfSharpCore initialized _orientation to Landscape.
I will create PR with my proposed changes.
EDIT: here's pull request
The PR has been merged, and I've tested the latest nuget package (1.3.47). It works fine now, so I'm closing this issue.
Sometimes, writing a property somehow causes the orientation of PDF to flip. If I remove the first property and write another one, the orientation flips back.
Here's example code, running on .NET 6 with PdfSharpCore 1.3.43:
var file = @"C:\a.pdf"; PdfSharpUsage.WriteFirstProperty(file); Console.WriteLine("First property written. Press enter to continue."); Console.ReadKey(); PdfSharpUsage.WriteSecondProperty(file);