| PDFsharp & MigraDoc Forum https://forum.pdfsharp.net/ |
|
| Height and Width Swapped in PDF Sharp 6.2.0 and Above https://forum.pdfsharp.net/viewtopic.php?f=2&t=4944 |
Page 1 of 1 |
| Author: | heathc [ Sat Feb 14, 2026 2:46 pm ] |
| Post subject: | Height and Width Swapped in PDF Sharp 6.2.0 and Above |
I am seeing issues starting with PDfSharp 6.2.0 and above, where the Height and Width can be swapped for some unknown reason. When I run the code snippet below targeting PdfSharp 6.1.1, hitting the same PDF Input File, I get this result: ![]() Retargeting the application to use PdfSharp 6.2.4, I get this result, again, hitting the exact same input pdf file: ![]() See the code below. Code: using PdfSharp.Drawing; using PdfSharp.Pdf; using System; using System.IO; string inputFilePath = "C:\\temp\\input.pdf"; string outputFilePath = "C:\\temp\\output-6.2.pdf"; if (File.Exists(outputFilePath)) File.Delete(outputFilePath); using var pdfDocument = new PdfDocument(); using var pdfForm = XPdfForm.FromFile(inputFilePath); pdfForm.PageNumber = 1; Console.WriteLine($"{inputFilePath} - XPdfForm.PointHeight : {pdfForm.PointHeight}"); Console.WriteLine($"{inputFilePath} - XPdfForm.PixelHeight : {pdfForm.PixelHeight}"); Console.WriteLine($"{inputFilePath} - XPdfForm.PointWidth : {pdfForm.PointWidth}"); Console.WriteLine($"{inputFilePath} - XPdfForm.PixelWidth : {pdfForm.PixelWidth}"); var sourcePageSizeInPoints = new XSize(pdfForm.PointWidth, pdfForm.PointHeight); var pdfPage = pdfDocument.AddPage(); pdfPage.Width = XUnit.FromPoint(sourcePageSizeInPoints.Width); pdfPage.Height = XUnit.FromPoint(sourcePageSizeInPoints.Height); var pageRect = new XRect(0, 0, sourcePageSizeInPoints.Width, sourcePageSizeInPoints.Height); using var gfx = XGraphics.FromPdfPage(pdfPage); gfx.Save(); gfx.DrawImage(pdfForm, pageRect); gfx.Restore(); pdfDocument.Save(outputFilePath); This is causing my application some issue where the PDF Generation of this data is wrong, making some items output in Landscape mode when they should be Portrait, and vice versa. A sample PDF that produces these inconsistent results between versions of PDF Sharp can be found here: https://github.com/user-attachments/files/24964546/input.pdf |
|
| Author: | Thomas Hoevel [ Mon Feb 16, 2026 6:34 am ] |
| Post subject: | Re: Height and Width Swapped in PDF Sharp 6.2.0 and Above |
This is a documented breaking change of PDFsharp 6.2.0. https://docs.pdfsharp.net/PDFsharp/Hist ... version-62 Quote: "Page orientation now works as expected The connection between page Width, Height, PageOrientation, and PageRotation was weird. It was replaced by a consistent concept. This is a breaking change." The media box for your file: /MediaBox [ 0 0 2592 1728 ] PDFsharp 6.2. returns the dimensions of the MediaBox, indicating the area that can be drawn. If you need the old behavior, then swap width and height if page rotation is 90° or 270°. |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|