Link to home
Start Free TrialLog in
Avatar of cool_dudeps
cool_dudeps

asked on

Print a pdf document - Urgent.

Hi

I want to print a pdf document through my VB program. I am new to VB, so a complete function would be of great help.

Thanks in advance
Avatar of tkalchev
tkalchev
Flag of Germany image

First, it is possible ONLY of you have Adobe Acrobat or Adobe Acrobat Reader installed on your computer.

Public 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

Public Const SW_HIDE = 0


Private Sub Command1_Click()


  ShellExecute Me.hwnd, "print", "c:\p.pdf", Null, Null, SH_HIDE
 

End Sub


Assuming your pdf file is c:\p.pdf
Ops, the correct is :

Private Sub Command1_Click()


  ShellExecute Me.hwnd, "print", "c:\p.pdf", "", "", SH_HIDE
 

End Sub

Replace Null with ""
Avatar of DocM
DocM


Private Sub Command1_Click()

    filename = "C:\Program Files\Adobe\Acrobat 5.0\Help\ENU\ACROBAT.PDF"
    result = PrintPdfDocument(filename)

End Sub

Function PrintPdfDocument(filename) As String

    On Error GoTo ErrorHandler

    strcommand = "C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe /p /h " & filename

    PrintPdfDocument = Shell(strcommand)

    Exit Function
   
ErrorHandler:
    PrintPdfDocument = "Error :" & Err.Number & Err.Description
End Function
Avatar of cool_dudeps

ASKER

Hello tkalchev and docm,

Thanks for the help, but the printout is not correct with the code you have given. It works fine with normal system fonts, but in case the document to be printed has some other fonts, it gives the following error:
"Unable to find or create the font 'ZTR6C.tmp,Bold'. Some characters may not display or print correctlty."

Please provide me with an appropriate solution to the above problem. Thanks again for the help in advance.

Regards.
ASKER CERTIFIED SOLUTION
Avatar of tkalchev
tkalchev
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi cool_dudeps,
This old question (QID 20566181) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.