Access VB - Acrobat - Rotate a page

I use this function regularly to add footers to acrobat documents and it works great

I recently researched a process to rotate the document 90 degrees before adding the footer but it does not rotate the pdf?

The code I added is

'loop through each page in the pdf file and and rotate it
                numPages = AcroPDDoc.GetNumPages()

                For PageNoVar = 1 To numPages - 1
                    'declare page
                    Dim page As AcroPDPage
                    'get next page
                    page = AcroPDDoc.AcquirePage(PageNoVar)
'                    Call page.SetRotate(270)
                    If page.SetRotate(180) Then

                    Else
                        'if we could not rotate the page
                        MsgBox "Could not rotate page"

                    End If
                Next

I found it at http://devblog.com.au/programmatically-rotate-pdf-files




------------------------------------------------------
Public Function AddPageNumbers(ByVal SourcePath As String, ByVal SourceFileName As String, ByVal DestPath As String, ByVal DestFileName As String, ByVal FrstPg As Double, ByVal MaxNoPgs As Double, ByVal FileNo As Double, ByVal DoYouWantToSendToPrinter As Integer, ByVal FontSize As Integer, ByVal FontColor As String) ', ByVal HeaderFooter As String)     Dim ex1 As String
    Dim App As Object, AVDoc As Object, AcroPDDoc As Object, AForm As Object
   
    Dim Ret As Long
    Dim sString As String * 255
    Dim PdfPrint As String, numPages As Integer, numPages1 As Integer, PageNoVar As Integer
       
    Dim sfile As String
    Dim sText As String
    Dim iFilenum As Integer
   
    Dim fileName As String '06-18-2011
   
    Set App = CreateObject("Acroexch.app")
    Set AVDoc = CreateObject("AcroExch.AVDoc")
   
    Set AForm = CreateObject("AFormAut.App") 'from AFormAPI
   
    If Right(SourcePath, 1) <> "\" Then SourcePath = SourcePath & "\"
    If Right(DestPath, 1) <> "\" Then DestPath = SourcePath & "\"
   
    fileName = SourceFileName '06-18-2011
    booleanresult = AVDoc.Open(SourcePath & SourceFileName, "")
       
       

    If booleanresult = True Then
        Set AcroPDDoc = AVDoc.GetPDDoc
       

'loop through each page in the pdf file and and rotate it
                numPages = AcroPDDoc.GetNumPages()

                For PageNoVar = 1 To numPages - 1
                    'declare page
                    Dim page As AcroPDPage
                    'get next page
                    page = AcroPDDoc.AcquirePage(PageNoVar)
'                    Call page.SetRotate(270)
                    If page.SetRotate(180) Then

                    Else
                        'if we could not rotate the page
                        MsgBox "Could not rotate page"

                    End If
                Next

'If HeaderFooter = "Footer" Then

         'Found Code at this web page https://forums.adobe.com/thread/721676?start=0&tstart=0
         'Java Script manual at http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf
         'Expert Exchange Question at http://www.experts-exchange.com/Web_Development/Document_Imaging/Adobe_Acrobat/Q_28569754.html
            ex1 = "  // Set Footer PageNo centered  " & vbLf & "  var Box2Width = 500  " & vbLf & "  for (var p = 0; p < this.numPages; p++)   " & vbLf & "   {   " & vbLf & "    var aRect = this.getPageBox(""Crop"",p);  " & vbLf & "    var TotWidth = aRect[2] - aRect[0]  " & vbLf & "     {  var bStart=(TotWidth/2)-(Box2Width/2)  " & vbLf & "         var bEnd=((TotWidth/2)+(Box2Width/2))  " & vbLf & "         var fp = this.addField(String(""xftPage""+p+1), ""text"", p, [bStart,30,bEnd,15]);   " & vbLf & "         fp.value = """
            ex1 = ex1 & fileName & " -- " & Month(Now) & "/" & Day(Now) & "/" & Year(Now) & " " & Hour(Now) & ":" & Minute(Now)
            ex1 = ex1 & " -- Page: "" + String(p+1)+ ""/"" + this.numPages;  " & vbLf & "         fp.textSize=" & FontSize & "; fp.textcolor = color.red; fp.readonly = true;  " & vbLf & "         fp.alignment=""left"";  " & vbLf & "     }  " & vbLf & "   }  "
'Else
'            ex1 = "  // Set Header PageNo centered  " & vbLf & "  var Box2Width = 500  " & vbLf & "  for (var p = 0; p < this.numPages; p++)   " & vbLf & "   {   " & vbLf & "    var aRect = this.getPageBox(""Crop"",p);  " & vbLf & "    var TotWidth = aRect[2] - aRect[0]  " & vbLf & "     {  var bStart=(TotWidth/2)-(Box2Width/2)  " & vbLf & "         var bEnd=((TotWidth/2)+(Box2Width/2))  " & vbLf & "         var fp = this.addField(String(""xftPage""+p+1), ""text"", p, [bStart,30,bEnd,15]);   " & vbLf & "         fp.value = """
'            ex1 = ex1 & fileName & " -- " & Month(Now) & "/" & Day(Now) & "/" & Year(Now) & " " & Hour(Now) & ":" & Minute(Now)
'            ex1 = ex1 & " -- Page: "" + String(p+1)+ ""/"" + this.numPages;  " & vbLf & "         fp.textSize=" & FontSize & "; fp.textcolor = color.red; fp.readonly = true;  " & vbLf & "         fp.alignment=""left"";  " & vbLf & "     }  " & vbLf & "   }  "
'
'End If
        AForm.Fields.ExecuteThisJavaScript ex1
    End If
   
   
    On Error Resume Next
   
    AcroPDDoc.Save 1, DestPath & DestFileName
   
    numPages = AcroPDDoc.GetNumPages()
   
        sfile = DestPath & "Files Printed " & Format$(Now, "YYMMDD") & ".txt"
        sText = IIf(FileNo < 10, "00", IIf(FileNo < 100, "0", "")) & FileNo & " --- " & "Printed " & MaxNoPgs & " of " & IIf(numPages < 10, "00", IIf(numPages < 100, "0", "")) & numPages & " --- " & SourcePath & SourceFileName & " --- " & DestPath & DestFileName
       
        If FileNo = 1 Then Kill DestPath & "Files Printed " & Format$(Now, "YYMMDD") & ".txt"
       
        iFilenum = FreeFile
        Open sfile For Append As iFilenum
        Write #iFilenum, sText
        Close #iFilenum
   
    If MaxNoPgs >= numPages Then
        MaxNoPgs = numPages
    End If
   
On Error GoTo 0
   
    AcroPDDoc.Close
    AVDoc.Close (True)
    App.Exit
   
    Set AcroPDDoc = Nothing
    Set AVDoc = Nothing
    Set App = Nothing


    If DoYouWantToSendToPrinter = 6 Then
        'http://help.adobe.com/livedocs/acrobat_sdk/10/Acrobat10_HTMLHelp/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Acrobat10_SDK_HTMLHelp&file=DevFAQ_UnderstandingSDK.22.31.html
        appPDF = """" & "C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\Acrobat.exe" & """"
        RetVal = Shell(appPDF & " /t /h /s /o " & """" & DestPath & DestFileName & """" & " Adobe PDF", 0)
    Else
   
    End If

End Function
rogerdjrAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Have you stepped through the code to insure the "Rotate" line is actually being fired? I don't have Adobe Pro, so can't run the code.
0
Jeffrey CoachmanMIS LiasonCommented:
Just curious...
(as I asked in your other question)
Whats the reason that you cannot reformat the report in Access to print rotated?

Seems like a lot of work to go through for all the code you have there, ...
Besides, simply rotating a PDF may result in the page breaks being incorrect, ...or the page numbering to be off as well...

Did you contact the author of this code, ...it seems that they would know more about this than us...?
The link also clearly states that this may not be the "full" solution:
PS: The reason I did not subit the full solution was due to Adobe having restrictions on been able to distribute their .DLL files. If you email me I will help you set the application up.


JeffCoachman
I have never had much luck with "Copy/pasting" complex code, ...then trying to figure out why it does not work.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I'm curious - how was Jeffs comment a solution to your question? It may have been, in that contacting the author may have given you the knowledge to enable this, but if that's the case, then you should post the details of that comment and accept that post as your solution, with Jeff's as an Assisted.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Acrobat

From novice to tech pro — start learning today.