-
Notifications
You must be signed in to change notification settings - Fork 224
Open
Description
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.
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 is attached here.
Metadata
Metadata
Assignees
Labels
No labels