From 3e025295800b8db9322677d68df9cf89db2adeac Mon Sep 17 00:00:00 2001 From: noctis0430 Date: Wed, 27 Sep 2023 13:39:31 +0800 Subject: [PATCH 1/2] Translate image based on /Rotate. --- PdfSharpCore/Pdf.Advanced/PdfFormXObject.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PdfSharpCore/Pdf.Advanced/PdfFormXObject.cs b/PdfSharpCore/Pdf.Advanced/PdfFormXObject.cs index 3a041ca9..3e18d762 100644 --- a/PdfSharpCore/Pdf.Advanced/PdfFormXObject.cs +++ b/PdfSharpCore/Pdf.Advanced/PdfFormXObject.cs @@ -212,9 +212,9 @@ internal PdfFormXObject(PdfDocument thisDocument, PdfImportedObjectTable importe // Translate the image such that its center lies on the center of the rotated bounding box double offset = (height - width) / 2; - if (height > width) + if (rotate == 90) matrix.TranslatePrepend(offset, offset); - else + else if (rotate == -90) matrix.TranslatePrepend(-offset, -offset); //string item = "[" + PdfEncoders.ToString(matrix) + "]"; From 8b5fa7ba1b2740ad7bc9f2326011c62e78538ec2 Mon Sep 17 00:00:00 2001 From: noctis0430 Date: Wed, 27 Sep 2023 13:39:46 +0800 Subject: [PATCH 2/2] Setup orientation based on /Rotate only. --- PdfSharpCore/Pdf/PdfPage.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PdfSharpCore/Pdf/PdfPage.cs b/PdfSharpCore/Pdf/PdfPage.cs index 94edfe8e..1d69ecb3 100644 --- a/PdfSharpCore/Pdf/PdfPage.cs +++ b/PdfSharpCore/Pdf/PdfPage.cs @@ -72,8 +72,7 @@ internal PdfPage(PdfDictionary dict) { // Set Orientation depending on /Rotate. int rotate = Elements.GetInteger(InheritablePageKeys.Rotate); - var mediaBox = Elements.GetArray(InheritablePageKeys.MediaBox); - if (Math.Abs((rotate / 90)) % 2 == 1 && mediaBox.Elements.GetReal(3) > mediaBox.Elements.GetReal(2)) + if (Math.Abs((rotate / 90)) % 2 == 1) _orientation = PageOrientation.Landscape; }