Printing a PDF using the Adobe Acrobat Control for ActiveX

  • Thread starter pubdude2003 via AccessMonster.com
  • Start date
P

pubdude2003 via AccessMonster.com

Hey all, anyone know how I can write some VB code specifying which pages of a
pdf to print?

I am using the following code to view the PDF's (On Current) in a form and I
noticed
that if I hit CTRL - P it will print the pdf (not the form) so I am wondering
if someone might be able to help me with the code to print specific pages of
the PDF being viewed.

Dim AcroApp As CAcroApp
Dim AVDoc As CAcroAVDoc
Dim PDDoc As CAcroPDDoc
Set AVDoc = CreateObject("AcroExch.AVDoc")
Set AcroApp = CreateObject("AcroExch.App")
Set PDDoc = AVDoc.GetPDDoc

Me.viewer.LoadFile ([file333])
 
P

pubdude2003 via AccessMonster.com

Solution: thanks to Chuck Reed for this marvelous code.

Option Explicit
Dim AcrDoc As CAcroAVDoc, AcrApp As CAcroApp, AcroPDDoc As CAcroPDDoc
Sub testprintpdf()
OpenAcrobat
PrintPDFDoc [Forms]![Form1]![Text3]
CloseAcrobat
End Sub
Sub testprintpdf2()
OpenAcrobat
PrintPDFDoc2 [Forms]![Form1]![Text3]
CloseAcrobat
End Sub
Private Sub OpenAcrobat()
Set AcrApp = CreateObject("AcroExch.App")
AcrApp.Minimize 1
DoEvents
End Sub

Private Sub PrintPDFDoc(x As String)
Dim AcrDoc As CAcroAVDoc, lngPages As Long

Set AcrDoc = CreateObject("AcroExch.AVDoc")
AcrDoc.Open x, "PDF Print"
DoEvents
Set AcroPDDoc = AcrDoc.GetPDDoc
lngPages = AcroPDDoc.GetNumPages
'OPTION 1
'AcrDoc.printPages 0, lngPages, 1, True, True 'HERE THE PRINT QUE DELETES
AFTER SPOOLING IF I USE THIS COMMAND AND TELL IT HOW MANY Pages I 'M PRINTING.

'OPTION 2
AcrDoc.printPages 0, 0, 1, True, True 'ONLY PRINTS FIRST PAGE WITH THIS
OPTION.
DoEvents
AcrDoc.Close True
DoEvents
Set AcrDoc = Nothing
DoEvents
End Sub
Private Sub PrintPDFDoc2(x As String)
Dim AcrDoc As CAcroAVDoc, lngPages As Long

Set AcrDoc = CreateObject("AcroExch.AVDoc")
AcrDoc.Open x, "PDF Print"
DoEvents
Set AcroPDDoc = AcrDoc.GetPDDoc
lngPages = AcroPDDoc.GetNumPages
'OPTION 1
AcrDoc.printPages 1, lngPages, 1, True, True 'HERE THE PRINT QUE DELETES
AFTER SPOOLING IF I USE THIS COMMAND AND TELL IT HOW MANY Pages I 'M PRINTING.

'OPTION 2
'AcrDoc.printPages 0, 0, 1, True, True 'ONLY PRINTS FIRST PAGE WITH THIS
OPTION.
DoEvents
AcrDoc.Close True
DoEvents
Set AcrDoc = Nothing
DoEvents
End Sub
Private Sub CloseAcrobat()
AcrApp.CloseAllDocs
AcrApp.Exit
Set AcrApp = Nothing
DoEvents
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top