PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Sat Feb 14, 2026 10:56 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sat Feb 14, 2026 2:46 pm 
Offline

Joined: Sat Feb 14, 2026 2:39 pm
Posts: 1
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:
Image

Retargeting the application to use PdfSharp 6.2.4, I get this result, again, hitting the exact same input pdf file:
Image

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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 77 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group