Click here to Skip to main content
15,886,069 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to be able to print a PDF without opening adobe. I have found a lot people use the shell method to accomplish that.
VB
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_HIDE = 0&
Private Sub PrintSilently()
    Dim strAction As String, FileName As String
    strAction = "print"
    FileName = "Test.pdf"
    'to print in background use SW_HIDE, else change this flag
    ShellExecute(Me.Handle, strAction, FileName, vbNullString, vbNullString, SW_HIDE)
End Sub

This might be fine, except that I have a second requirement that I need to be able to set more advanced printing preferences. For example, printing on different sized paper, selecting which tray of the printer to take from, stapling, three-hole punching....the crazy stuff that real hard core printers can do. I can't see how using the shell method would allow me to specify these settings. And, more importantly, I have yet to figure out a way to print using the advanced preferences. So, I'm looking for any advice.

I'm even open to using a third-party component but was hoping not to have to spend money to solve this issue. So any recommendations of third-party components are also welcome.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900