[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Print a pdf document - Urgent.

Posted on 2003-03-28
6
Medium Priority
?
274 Views
Last Modified: 2007-12-19
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
0
Comment
Question by:cool_dudeps
6 Comments
 
LVL 9

Expert Comment

by:tkalchev
ID: 8223789
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
0
 
LVL 9

Expert Comment

by:tkalchev
ID: 8223795
Ops, the correct is :

Private Sub Command1_Click()


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

End Sub

Replace Null with ""
0
 
LVL 3

Expert Comment

by:DocM
ID: 8223809

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
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:cool_dudeps
ID: 8229860
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.
0
 
LVL 9

Accepted Solution

by:
tkalchev earned 200 total points
ID: 8229937
then use the acrobat pdf activex control to handle printing
0
 

Expert Comment

by:CleanupPing
ID: 8531433
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

640 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question