Printing The first 5 pages of a PDF file using Access VBA

I want to prin the 1st 5 pagese of each of the pdf files in a directory.

Can anybody help with this?
Who is Participating?

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

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.

I think zone is wrong.
If you have Acrobat reader installed, you should have Adobe PDF Reader ActiveX.
Insert it to your form. Then you can print your file with this code:
Me.AcroPDF5.LoadFile PDFFileFullName
Me.AcroPDF5.printPages 1, 5

AcroPDF5 - name of inserted ActiveX control.
Search for pdf file names you can with this example:
rogerdjrAuthor Commented:
I tried inserting the print pages command (    AcroPDDoc.PrintPages 1, 5) in my code and it hangs with an error message:

"Object doesn't support this property or method"

Public Function AddPageNumbers(ByVal Path As String, ByVal Path1 As String, ByVal filename As String) 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

    Set App = CreateObject("")
    Set AVDoc = CreateObject("AcroExch.AVDoc")
    Set AForm = CreateObject("AFormAut.App") 'from AFormAPI
    booleanresult = AVDoc.Open(Path, "")
    If booleanresult = True Then
        Set AcroPDDoc = AVDoc.GetPDDoc
        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=6; fp.textColor =;  fp.readonly = true;  " & _
        vbLf & "         fp.alignment=""left"";  " & vbLf & "     }  " & vbLf & "   }  "

        AForm.Fields.ExecuteThisJavaScript ex1
    End If
    AcroPDDoc.PrintPages 1, 5
    AcroPDDoc.Save 1, Path1

    AVDoc.Close (True)
    Ret = FindWindowWild(0, "Adobe*")
    Call GetWindowText(Ret, sString, 255)
    Ret = FindWindow(vbNullString, sString)
    PostMessage Ret, WM_CLOSE, CLng(0), CLng(0)

    Set AcroPDDoc = Nothing
    Set AVDoc = Nothing
    Set App = Nothing
End Function
This code:
Set App = CreateObject("")
Set AVDoc = CreateObject("AcroExch.AVDoc")
Set AForm = CreateObject("AFormAut.App") 'from AFormAPI

is working only with full Adobe Acrobat installed.
Try to use ActiveX as I've recommended in my comment #35225653
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

rogerdjr: First things first. Could you please confirm if you have Acrobat Reader Installed or Acrobat Pro?

rogerdjrAuthor Commented:
I have

C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Acrobat.exe


C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe

Can't seem to find the ActiveX as recommended in comment #35225653, or fgure out how to install and use it?
You have both full Acrobat and Acrobar reader installed and you should be able to use your routine.
Read this:
and try:
AcroPDDoc.PrintPages 0, 4, 1, True, True
If your document may have less then 5 pages, may be better to count pages before printing
rogerdjrAuthor Commented:
Got it to work - this the code FYI.

Do you have a reference that allows me to specify additional acrobat printing parameters for acrobat docs (e.g. print to fit, rotate,, etc.) - they show-up on the pop-up menu in acrobat and it would be nice to be able to set and reset them with vba.


Public Function PrintPdfFile(ByVal PdfPath As String, ByVal PdfFileNm As String, ByVal PdfFirstPageToPrint As Integer, ByVal PdfMaxPagesToPrint As Integer) As String
    Dim PdfPathAndFile As String
    Dim AVDoc As Acrobat.AcroAVDoc
    Dim retcd As Integer
    If Right(PdfPath, 1) = "\" Then
        PdfPathAndFile = PdfPath & PdfFileNm
        PdfPathAndFile = PdfPath & "\" & PdfFileNm
    End If
    Set AVDoc = CreateObject("AcroExch.AVDoc")
    retcd = AVDoc.Open(PdfPathAndFile, "Title")    ' pathname of pdf file to be opened
    If retcd <> -1 Then
'        MsgBox ("Failed to open PDF document " & PdfPathAndFile)
        Exit Function
    End If

    'AVDoc.PrintPages(firstPage, numPages, 2, true, true)
    If PdfMaxPagesToPrint >= 2 Then PdfMaxPagesToPrint = PdfMaxPagesToPrint - 1  'allows for the fact that the first page is page 0
    If PdfFirstPageToPrint >= 1 Then PdfFirstPageToPrint = PdfFirstPageToPrint - 1 'allows for the fact that the first page is page 0
    retcd = AVDoc.PrintPages(PdfFirstPageToPrint, PdfMaxPagesToPrint, 0, 1, 1)         ' this prints the number of pages specified by PdfMaxPagesToPrint (i.e. page 0)
    AVDoc.Close (1)

End Function
You can use Object Browse in VBA editor. Select proper Acrobat library and you can see available functions

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
rogerdjrAuthor Commented:

Found this -
Function PrintPagesSilent(nFirstPage As Long, nLastPage As Long, nPSLevel As Long, bBinaryOk As Long, bShrinkToFit As Long) As Boolean
    Member of Acrobat.AcroAVDoc
    Prints a specified range of pages without displaying any dialog box.

Neat tool - I haven't used the object browser before.

Learn something new every day
rogerdjrAuthor Commented:

Great support once again
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
Web Development Software

From novice to tech pro — start learning today.