Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print pdfs from VB

Status
Not open for further replies.

ndp

Programmer
Mar 3, 2003
121
US
Hi,
I have pdfs in a folder. I want to create a user application where user can see the contents of the folder, select the pdf and send it to a printer to print. I can show the contents of the folder, but I don't know how to send the selected file to printer and get it printed.

Please!!! Any suggestion is welcome!
Thanks in advance.
ndp
 
If you are sending it to the default printer you can use the ShellExecute API to do this. Search the form for an example.
 
I was using ShellExecute and in some machines it works fine but with some net printers sometimes fails...
I changed to use PDF Api
Add in your project Acrobat.tlb reference

then you can use this function you give the full path of the file as parameter.

Function PrintPDF(strFileName As String) As Boolean
Dim AVDoc As CAcroAVDoc
Dim PDDoc As CAcroPDDoc
Dim iNumPages As Integer

On Error GoTo ErrorHandler

Set AVDoc = CreateObject("AcroExch.AVDoc")

' Open the document
AVDoc.Open strFileName, ""

' Calculate the number of page in the document
Set PDDoc = AVDoc.GetPDDoc
iNumPages = PDDoc.GetNumPages

' Print the document
AVDoc.PrintPages 0, iNumPages - 1, 2, True, True

' Close the document
AVDoc.Close True

Set AVDoc = Nothing
Set PDDoc = Nothing

PrintPDF = True

Exit Function

' Set error handler for this section
ErrorHandler:
PrintPDF = False
End Function


Someone who has never served other is someone that has never lived...
 
Thanks so much bjd4jc and daca. That is excellent suggestion. I will test both the methods on user's computer. Which ever works fine, I will use it.
But, my main concern is how to use a selected printer. Because, different pdfs will be printed on different printer. User will select a printer and tray. Can you suggest a way to do it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top