49 lines
1.7 KiB
VB.net
49 lines
1.7 KiB
VB.net
Imports System.IO
|
|
Imports GdPicture14
|
|
|
|
Public Class FixPageRotation
|
|
''' <summary>
|
|
''' 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.
|
|
''' </summary>
|
|
''' <param name="pFilePath"></param>
|
|
''' <returns></returns>
|
|
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
|