From 4d34eb7adc43109f02b62a2f21ba01befdbaeee8 Mon Sep 17 00:00:00 2001 From: OlgunR Date: Tue, 22 Apr 2025 10:26:03 +0200 Subject: [PATCH] Funktion zur Behebung der Rotation - Class EnvelopeEditorController, Class FixPageRotation --- .../Controllers/EnvelopeEditorController.vb | 8 +++- .../EnvelopeGenerator.Form.vbproj | 1 + .../Helper/FixPageRotation.vb | 48 +++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 EnvelopeGenerator.Form/Helper/FixPageRotation.vb diff --git a/EnvelopeGenerator.Form/Controllers/EnvelopeEditorController.vb b/EnvelopeGenerator.Form/Controllers/EnvelopeEditorController.vb index fffe99c4..b26eec0a 100644 --- a/EnvelopeGenerator.Form/Controllers/EnvelopeEditorController.vb +++ b/EnvelopeGenerator.Form/Controllers/EnvelopeEditorController.vb @@ -156,7 +156,11 @@ Public Class EnvelopeEditorController Public Async Function CreateDocument(pDocumentFilePath As String) As Threading.Tasks.Task(Of EnvelopeDocument) Try - Dim oFileInfo = New FileInfo(pDocumentFilePath) + Dim oFixedPath = FixPageRotation.FixPageRotation(pDocumentFilePath) + If oFixedPath <> pDocumentFilePath Then + Logger.Info("PageRotation has been reseted to 0.") + End If + Dim oFileInfo = New FileInfo(oFixedPath) Dim oTempFiles As New TempFiles(State.LogConfig) Dim oTempFilePath = Path.Combine(oTempFiles._TempPath, Guid.NewGuid().ToString + oFileInfo.Extension) @@ -172,7 +176,7 @@ Public Class EnvelopeEditorController .FileNameOriginal = oFileInfo.Name, .Thumbnail = Thumbnail.GetThumbnailFromPDFFile(oTempFilePath), .PageCount = Thumbnail.GetPageCount(oTempFilePath), - .Byte_Data = ReadFile(pDocumentFilePath) + .Byte_Data = ReadFile(oFixedPath) } Return oDocument diff --git a/EnvelopeGenerator.Form/EnvelopeGenerator.Form.vbproj b/EnvelopeGenerator.Form/EnvelopeGenerator.Form.vbproj index 789eba38..869f1ee8 100644 --- a/EnvelopeGenerator.Form/EnvelopeGenerator.Form.vbproj +++ b/EnvelopeGenerator.Form/EnvelopeGenerator.Form.vbproj @@ -362,6 +362,7 @@ Form + diff --git a/EnvelopeGenerator.Form/Helper/FixPageRotation.vb b/EnvelopeGenerator.Form/Helper/FixPageRotation.vb new file mode 100644 index 00000000..58c7a8c9 --- /dev/null +++ b/EnvelopeGenerator.Form/Helper/FixPageRotation.vb @@ -0,0 +1,48 @@ +Imports System.IO +Imports GdPicture14 + +Public Class FixPageRotation + ''' + ''' Checks if there are any rotations in the document. If so, normalizes the page rotation to 0 without affecting its visual appearance. + ''' Creates and uses a new document with the corrected properties. + ''' Fixes the issue of annotations being rotated to match the page's rotation. + ''' + ''' + ''' + Public Shared Function FixPageRotation(pFilePath As String) As String + + Dim oFolder As String = Path.GetDirectoryName(pFilePath) + Dim oChanged As Boolean = False + + Using gdpicturePDF As New GdPicturePDF() + + Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile(pFilePath, True) + If status = GdPictureStatus.OK Then + + Dim count As Integer = gdpicturePDF.GetPageCount() + For i As Integer = 1 To count + If gdpicturePDF.SelectPage(i) = GdPictureStatus.OK Then + Dim rotation As Integer = gdpicturePDF.GetPageRotation() + If rotation <> 0 Then + gdpicturePDF.NormalizePage() + oChanged = True + End If + End If + Next + + End If + + If oChanged Then + Dim newFilesPath As String = Path.Combine(oFolder, "RotationFixed_" & Path.GetFileName(pFilePath)) + If gdpicturePDF.SaveToFile(newFilesPath) = GdPictureStatus.OK Then + Return newFilesPath + End If + End If + + End Using + + Return pFilePath + + End Function + +End Class