Print external pdf file

oxicottin

Learning by pecking away....
Local time
Today, 17:15
Joined
Jun 26, 2007
Messages
888
Hello, I have a textbox (txtUnboundSafetyCPath) that displays the full path to a .pdf document I selected. How can I print the .pdf using that path? I also need it to print it hidden....

Thanks,
 
I found some code HERE from arnelgp that works but it opens the pdf and prints then closes. Is there a way I can hide the opening of it?
 
CreateObject("Shell.Application").Namespace(0).ParseName("C:\Users\sola\Documents\dogexport.pdf").InvokeVerb ("Print")
 
CreateObject("Shell.Application").Namespace(0).ParseName("C:\Users\sola\Documents\dogexport.pdf").InvokeVerb ("Print")
@oleronesoftwares your code does work but just like the other one the doc closes but acrobat stays open?

Code:
Dim docpath As String

docpath = Me.txtUnboundSafetyCPath

CreateObject("Shell.Application").Namespace(0).ParseName(docpath).InvokeVerb ("Print")
 
so you want acrobat to close after printing?

Yes, it opens the file prints the file and closes the file BUT leaves Acrobat Reader open in my system tray. How do I get that to close as well?

Thanks,
 
Hi,
the code works fine at my end, i have put a video on youtube for you to watch
 
@oleronesoftwares I open a .pdf and it opens prints and closes but it leaves the reader behind open. I attached a image of my tasks after its done.

I did try a word document like in your video and everything was fine its just with a .pdf
 

Attachments

  • Capture.JPG
    Capture.JPG
    22.6 KB · Views: 241
Last edited:
Unfortunately, since i don't have acrobat reader, i might not be able to help out, i use browsers to open my pdf documents.

You can try any non-ms office application on your system, to see if the routine will work well, if it does then will can probe further to see why pdf is not working, if it doesn't then will know the routine only works with ms office.
 
hi @oxicottin you can try this code, but you have to change the WINWORD.exe to the name of the executable file of adobe acrobat reader, i think it is Acrobat.exe, but please confirm.

Code:
Private Sub Command22_Click()
            Dim vPID As Variant
            vPID = Shell("WINWORD.exe ""C:\Users\sola\Documents\focus.docx""", vbNormalFocus)
            CreateObject("Shell.Application").Namespace(0).ParseName("C:\Users\sola\Documents\focus.docx").InvokeVerb ("Print")
            Call Shell("TaskKill /F /PID " & CStr(vPID), vbHide)
End Sub
 
@oleronesoftwares I got it to close the reader with:

Code:
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Sub Close_Acrobat_Reader()
    Dim hwnd    As Long
    Dim nRet    As Long

    Const WM_CLOSE As Long = &H10
    hwnd = FindWindow("AcrobatSDIWindow", vbNullString)

    If hwnd <> 0 Then nRet = SendMessage(hwnd, WM_CLOSE, 0, 0)
End Sub
 
there is a Command line program that prints pdf directly to your Default printer.
it doesn't use Acrobat or any Pdf viewer.

PDFtoPrinter for Windows (columbia.edu)

i have tried it:
Code:
Private Sub t()
    Dim pdfExe As String
    Dim pdfToPrint As String
    'set variable to the path of pdfToPrinter.exe
    pdfExe = "C:\VI\pdfToPrinter.exe"
    'set the path and name of pdf to print
    pdfToPrint = Environ$("userprofile") & "\desktop\Now And Forever chords with lyrics by R...pdf"
    
    Shell pdfExe & " " & """" & pdfToPrint & """"
End Sub
 
@arnelgp I don't have pdfToPrinter.exe on my PC and IT most likely wont install....
 
you don't install it.
download and run it.
 

Users who are viewing this thread

Back
Top Bottom