rogerdjr
asked on
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(Page NoVar)
' 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.AVD oc")
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(Page NoVar)
' 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 https://www.experts-exchange.com/questions/28569754/Editing-an-Acrobat-PDF-file-to-add-page-footers-from-Access-2013.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)-(Box2W idth/2) " & vbLf & " var bEnd=((TotWidth/2)+(Box2Wi dth/2)) " & vbLf & " var fp = this.addField(String(""xft Page""+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)-(Box2W idth/2) " & vbLf & " var bEnd=((TotWidth/2)+(Box2Wi dth/2)) " & vbLf & " var fp = this.addField(String(""xft Page""+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.ExecuteThisJa vaScript 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
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(Page
' 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.AVD
Set AForm = CreateObject("AFormAut.App
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(Page
' 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 https://www.experts-exchange.com/questions/28569754/Editing-an-Acrobat-PDF-file-to-add-page-footers-from-Access-2013.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
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
' 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.ExecuteThisJa
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
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.