Avatar of kriskyk
kriskyk
 asked on

Open and Print PDF file

I'm trying to get a specific PDF to open and print. Using the code below I am able to get the desired PDFs to open but not print. I've looked at many examples and they appear to be using objects not availible in my library. I've added the following libraries:
Adobe Acrobat 8.0 Type Library
Acrobat Access 3.0 Type Library
Adobe Acrobat 8.0 Browser Control Type Library 1.0
AcroIEHelper 1.0 Tpye Library

Any help with the code or any additional libraries that I'm not using will be greatly appreciated.
Option Compare Database
 
 
Private Const SW_SHOWNORMAL = &H1&
 
Private Declare Function ShellExecuteA Lib "shell32" ( _
  ByVal hwnd As Long, _
  ByVal lpszOp As String, _
  ByVal lpszFile As String, _
  ByVal lpszParams As String, _
  ByVal LpszDir As String, _
  ByVal FsShowCmd As Long) As Long
 
 
Public Sub OpenPDF(ByVal szPDFLocation As String)
  
  Dim Success As Long
  
  ' If the function succeeds, it returns a value greater than 32.
  Success = ShellExecuteA(0, "open", szPDFLocation, vbNullString, vbNullString, SW_SHOWNORMAL)
  
  If Success > 32 Then
    
    Debug.Print "Success"
    
  Else
    ' For a list of error codes.
    ' http://msdn.microsoft.com/en-us/library/bb762153(VS.85).aspx
    Debug.Print "Error= " & Success
    
  End If
 
End Sub
 
 
Private Sub Command1_Click()
Dim NameOfPDF As String
Dim AVDoc As AcroAVDoc
 
 
NameOfPDF = 9814634 'to be replaced by a passed varible
OpenPDF "H:\Accounting\Finance-Sales & Marketing\SDamm\WIP\USFS MOD\Downloads\INVOICES\" & NameOfPDF & "-1.pdf"
OpenPDF "H:\Accounting\Finance-Sales & Marketing\SDamm\WIP\USFS MOD\Downloads\INVOICES\" & NameOfPDF & "-2.pdf"
 
End Sub

Open in new window

Microsoft AccessAdobe Acrobat

Avatar of undefined
Last Comment
msacc97

8/22/2022 - Mon
Wayne Michael

I use gnostice toolkit

www.gnostice.com

Wayne Michael

kriskyk

ASKER
I was able to get it to print using the below code. however it donesnt close, leaving multiple instances of acrobat opened.
Option Compare Database
 
 
Private Const SW_SHOWNORMAL = &H1&
 
Private Declare Function ShellExecuteA Lib "shell32" ( _
  ByVal hwnd As Long, _
  ByVal lpszOp As String, _
  ByVal lpszFile As String, _
  ByVal lpszParams As String, _
  ByVal LpszDir As String, _
  ByVal FsShowCmd As Long) As Long
 
Public Sub PrintPDF(ByVal szPDFLocation As String)
  
  Dim Success As Long
  
  ' If the function succeeds, it returns a value greater than 32.
  Success = ShellExecuteA(0, "print", szPDFLocation, vbNullString, vbNullString, SW_SHOWNORMAL)
  
  If Success > 32 Then
    
    Debug.Print "Success"
    
  Else
    ' For a list of error codes.
    ' http://msdn.microsoft.com/en-us/library/bb762153(VS.85).aspx
    Debug.Print "Error= " & Success
    
  End If
 
End Sub
 
 
Private Sub Command2_Click()
Dim NameOfPDF As String
 
NameOfPDF = 9814634 'to be replaced by a passed varible
PrintPDF "H:\Accounting\Finance-Sales & Marketing\SDamm\WIP\USFS MOD\Downloads\INVOICES\" & NameOfPDF & "-1.pdf"
PrintPDF "H:\Accounting\Finance-Sales & Marketing\SDamm\WIP\USFS MOD\Downloads\INVOICES\" & NameOfPDF & "-2.pdf"
 
End Sub

Open in new window

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Wayne Michael

I had the same issue so I switched to Gnostice....

I did write an adobe kill app in .Net to solve that,  but that is not a great solution.

you can open adobe minimized.

msacc97

kriskyk,

Did you try this?

AcroRd32.exe /t "C:\test.pdf"


http://support.adobe.com/devsup/devsup.nsf/docs/52080.htm
ASKER CERTIFIED SOLUTION
msacc97

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
msacc97

kriskyk,

Good luck and thank you for the points!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.