Print without using a Printdialog

jlmacdonald

Member
Joined
Apr 16, 2007
Messages
7
Programming Experience
1-3
This is probably an easy question but the more I've searched the more confused I got. I have a printbot program that will print out a batch of HTML files in a pending directory and then move them to a printed directory. The snag that I've run into is the actual printing. I don't need or want to open the HTML documents before printing. The snippet of code I have been using is:

VB.NET:
PrivateSub PrintFile(ByVal filePath AsString)
 
Dim myprocess AsNew Process
Dim psi AsNew ProcessStartInfo
psi.FileName = filePath
psi.Verb = "print"
myprocess.StartInfo = psi
myprocess.Start()
 
EndSub
This will work fine but it will launch a print dialog box for every file it print and because I need it automated to print batches I can't have it displayed. I have also looked at the printdocument and couldn't get over how complicated it was. I just need it to print an HTML document without opening it up first and have the program to use the default printer. Is there an easy way to do this?

Thanks for any help.
 
If you're getting a print dialog that sounds as a setting with your printer. I'm not getting a print dialog when I run the code. Or maybe you are annoyed that Notepad or something briefly flashes by? See this also, two lines of code to print a text document using the PrintDocument, http://www.vbdotnetforums.com/showthread.php?t=18016
 
It works like a charm....except that it prints out the HTML code as text. Is there a way that I can pass something into the TextPrint class so it will use IE so it can render the HTML and print that and not the code? Or does the TextPrint just print text? (It's kind of implied by the name but I thought I'd ask.) :)
 
You can use the Webbrowser control to display the rendered webpage and call its Print method.
If I remember correctly the control have to be attached to form, but don't have to be visible, for the printing to work.
 
Back
Top