# Send files to a print driver in visual basic



## asedt (Jun 18, 2008)

Hi

I want to send files to a print driver in Visual Basic 2005.

I need to know how to select printer, select file, and how to send it.

I will send a lot of different files and the driver (fineprint software) will take care of them.

edit: only need to print pdf-files to the driver.


----------



## astrella (Jun 27, 2008)

The best way to do so would be to get a HDC from the printer driver using a common dialog box.. i assume you are using vb6 and the print matter is in richtext box so here is a solution...

CommonDialog1.PrinterDefault = True
CommonDialog1.CancelError = True
' Set flags - no page numbers, return the selected printer
CommonDialog1.Flags = cdlPDReturnDC + cdlPDNoPageNums
If RichTextBox1.SelLength = 0 Then
CommonDialog1.Flags = CommonDialog1.Flags + cdlPDAllPages
Else
CommonDialog1.Flags = CommonDialog1.Flags + cdlPDSelection
End If

' Enables error handling to catch cancel error
On Error Resume Next

' display the print dialog box
CommonDialog1.ShowPrinter

If Err Then
' This code runs if the dialog was cancelled
MsgBox "Dialog Cancelled"
Exit Sub
End If
' Prints the contents of RichTextBox
RichTextBox1.SelPrint (Printer.hDC)

hope u find it usefull :up:


----------

