Skip to main content
Participant
August 3, 2018
Question

how to rotate pdfs via a api

  • August 3, 2018
  • 3 replies
  • 1263 views

hello

we scan plans, about 300, i would rotate  all files in a folder via a vb.net program.

Sub Drehunng(inRichtung As String, inPDF As System.IO.FileInfo)

        Dim PDFout1 As New Acrobat.AcroPDDoc

        Dim Seite As Acrobat.AcroPDPage

        PDFout1.Open(inPDF.FullName)

        For i As Long = 0 To PDFout1.GetNumPages - 1

            Seite = PDFout1.AcquirePage(i)

            Select Case inRichtung

                Case "n"

                    Seite.SetRotate(0)

                Case "l"

                    Seite.SetRotate(270)

                Case "r"

                    Seite.SetRotate(90)

                Case "k"

                    Seite.SetRotate(180)

            End Select

        Next

        PDFout1.Save(1, inPDF.FullName)

        PDFout1.Close()

        gApp.CloseAllDocs()

    End Sub

it rotates but only from the orginal scanned pdf direction and not from the direction whitch is actually  saved.

How can we rotate from the actually saved direction and not from the orginal scanned pdf direction?

This topic has been closed for replies.

3 replies

Participating Frequently
May 21, 2024

Hi

To rotate the pages based on the current saved direction, you'll need to retrieve the existing rotation angle of each page before applying the new rotation. Here's how you can modify your code to achieve this:

 

Sub Drehunng(inRichtung As String, inPDF As System.IO.FileInfo)
    Dim PDFout1 As New Acrobat.AcroPDDoc
    Dim Seite As Acrobat.AcroPDPage

    PDFout1.Open(inPDF.FullName)

    For i As Long = 0 To PDFout1.GetNumPages - 1
        Seite = PDFout1.AcquirePage(i)

        ' Get the current rotation angle of the page
        Dim currentRotation As Integer
        currentRotation = Seite.GetRotate()

        ' Calculate the new rotation angle based on the current saved direction and the desired rotation
        Dim newRotation As Integer
        Select Case inRichtung
            Case "n"
                newRotation = currentRotation + 0
            Case "l"
                newRotation = currentRotation + 270
            Case "r"
                newRotation = currentRotation + 90
            Case "k"
                newRotation = currentRotation + 180
        End Select

        ' Set the new rotation angle for the page
        Seite.SetRotate(newRotation)
    Next

    PDFout1.Save(1, inPDF.FullName)
    PDFout1.Close()
    gApp.CloseAllDocs()
End Sub

 

In this modified code, we first retrieve the current rotation angle of each page using the GetRotate() method. Then, we calculate the new rotation angle by adding the desired rotation angle to the current rotation angle. Finally, we set the new rotation angle for the page using the SetRotate() method.

This way, the rotation will be based on the current saved direction of each page rather than the original scanned PDF direction.

Elisenda

Participant
May 14, 2024

I thank you very much When I'm helpless @฿69869766

Legend
August 3, 2018

You should not just use SetRotate but you should factor in the original rotation via GetRotate. Even pages which seem upright may have a rotation value.