Remote Printing - Help!

optink

New member
Joined
Oct 18, 2006
Messages
3
Programming Experience
Beginner
Hello -

I need to print various files (PDF, TIF, etc.) directly to a printer without user intervention. The application is a VB.NET windows service. The printer name will be given to me by either IP address or a UNC path \\server\printer. The printers will not be installed locally to the machine running this application. I will be given different printers for the various files.

I found a way to use the System.Diagnostics.ProcessStartInfo class to print a file using the printto verb. However, this assume that the printer is defined on the machine. Is there anyway I can print to a remote or network printer without one being defined locally? I was thinking about the Internet Printing Protocol, but I have never seen this used within a VB.NET application.

Thanks!
 
this might work for you.

I used this to print to networked printer.
this only prints to the default printer.
I dont know what level your on so ill be breif.

So if you can display your info in a web browser control
Use the webbrowser1.print method, this is good because it will allow you to have some fancy html formatting and easily display images ect, all I done was create a txt file with an html text template and read into an array and inserted the text i wanted to display at the correct lines, I found the lines needed not by counting but by looking at it in front page. Once the array has the appropriate data, I assigned that to the curent document in the webbrowser control. and created a button with this verry simple print code
VB.NET:
webbrowser.print
Its that easy. Heres a simple example

VB.NET:
Public Function Set_Content(byval strStreet as string and so on)
     dim content as string
[SIZE=2]     content = [/SIZE][SIZE=2][COLOR=#800000]"<html><body><font color='red' size='5'><center>Property Sold "[/COLOR][/SIZE]
[SIZE=2][COLOR=#800000]             _& </center></font><br><br><br> Property Address : "[/COLOR][/SIZE]
[SIZE=2]             _& strStreet & [/SIZE][SIZE=2][COLOR=#800000]", "[/COLOR][/SIZE][SIZE=2] & strSuburb & [/SIZE][SIZE=2][COLOR=#800000]", "[/COLOR][/SIZE][SIZE=2] & strCity & [/SIZE][SIZE=2][COLOR=#800000]"<br><br> Lister : "[/COLOR][/SIZE]
[SIZE=2]             _& strName & [/SIZE][SIZE=2][COLOR=#800000]"<br><br>Seller : "[/COLOR][/SIZE][SIZE=2] & strSeller & [/SIZE][SIZE=2][COLOR=#800000]"<br><br>Price : "[/COLOR][/SIZE]
[SIZE=2]             _& Format(decPrice, [/SIZE][SIZE=2][COLOR=#800000]"c"[/COLOR][/SIZE][SIZE=2]) & [/SIZE][SIZE=2][COLOR=#800000]"</body></html>"[/COLOR][/SIZE]
[COLOR=#800000]     Return content[/COLOR]
[SIZE=2][COLOR=#800000]End Sub[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#800000]Sub display[/COLOR][/SIZE]
[SIZE=2][COLOR=#800000][SIZE=2]     WebBrowser1.DocumentText = Set_Content[/SIZE][/COLOR]
[/SIZE][SIZE=2][COLOR=#800000]End Sub[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#800000]Sub Print_Document[/COLOR][/SIZE]
[SIZE=2][COLOR=#800000][SIZE=2]     WebBrowser1.Print()[/SIZE][/COLOR]
[/SIZE][SIZE=2][COLOR=#800000]End Sub[/COLOR][/SIZE]
Not sure about this working as is. I just wrote it in here not in VS. but if this can work you should get the point.
 
Sorry, I should have clarafied... My application is a Windows Service that runs on a Windows 2000 server, not a Web Service. I basically want to print to various network printers. These printers will not be defined on the local machine, so there is no default printer. The ony way I could get this to work is to add the network printer to the machine and then delete it after processing, which does not appear to be good logic. There has to be a way to print without having a printer added to the machine.
 
This should work:
VB.NET:
Dim pd As New Printing.PrintDocument
pd.PrinterSettings.PrinterName = "[URL="file://\\machinename_or_ip\printername"]\\machinename_or_ip\printername[/URL]"
If pd.PrinterSettings.IsValid = True Then

End If
 
Find computers and printers

There is a way to get all the printers and computers attached to your network, I just cant remember how.
It is fairly simple because I done it when I was just starting. I think the source for that is in my network drive at my learning place. I will look tomorrow.
And then use the above posts code.
 
There is a way to get all the printers and computers attached to your network, I just cant remember how.
Just query the remote machine with WMI, asking for Name properties of Win32_Printer works well.
 
Thanks for the replies. You guys gave me some pretty good ideas. I think using a combination of the Printing.PrintDocument object and the System.Diagnostics.Process object, should solve my problem. I have seen many posts on this same topic, so I will go ahead and update this thread with some sample code, just in case someone else runs into this.
 
Back
Top