Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send document to printer with C#

Tags:

c#

printing

I've been given a requirement for an internal web application to send documents to a printer transparently. The idea would be that the user can select their nearest printer, and the web application would send their print jobs to the printer they selected.

The first printer we have to roll out against are Canons, so my questions is: How would I go about sending a document to print aross the network to a specific Canon? The type of Cannon is question is an iR5570 and the documents that will be said will mainly be Word and PDFs

I'm currently working my way through the terrible, IE only Canon Developer site, but I'm kinda hoping someone can point me in the right direction or point me at a 3rd party assembly :)

like image 862
Chris Canal Avatar asked Oct 20 '08 14:10

Chris Canal


People also ask

How do I send a document to my printer?

Open the document or file you want to print. In the top portion of the program window or browser you're using, open the file menu by clicking File and then Print from the drop-down menu.

Does C have a print function?

Print Function in C, C++, and Python Print function is used to display content on the screen. Approach: Some characters are stored in integer value inside printf function. Printing the value as well as the count of the characters.

What is the code to print in C?

In C programming there are several functions for printing formatted output. The printf() function is used to format and print a series of characters and values to the standard output.

How does a computer send data to a printer?

It might be connected physically to a file server or client computer by a parallel, serial or USB connection. Dedicated, network, print-server hardware devices connect directly to a printer via a parallel or USB connection and to the network wirelessly or by using an RJ45, Ethernet cable connection.


1 Answers

The key phrase in that question is 'web application'.

In a normal web app using only HTML+Javascript over HTTP, you can't just send a document directly to a printer. That's one of the reasons web browsers exist, and without that functionality everyone's printer would collect the same kind of junk that a public fax machine does.

So you need some kind of work-around. One option is to build on a common plug-in, like flash, silverlight, java applet, or even something like greasemonkey. Another is a custom plug-in, like a hosted winforms control or custom browser extension.

You are very fortunate, in that it looks like you have complete control (or knowlege of) the deployment environment, and that this environment if fairly homogenous. This means you have an additional option that others have started to explore. If you can install all of the printers in your environment to the web server, then it's fairly easy using the built-in .Net printer classes (in the System.Drawing.Printing namespace) to list out those printer, either show them to the user so they can pick or keep some kind of IP to Printer mapping table, and then print directly to that printer from your web app. Note that this scheme may require your app to run at a higher level of trust than would otherwise be required.

Now it comes to actually printing your PDF's and word documents. For acrobat, check this link:
http://support.adobe.com/devsup/devsup.nsf/docs/52080.htm (Wayback machine)
Note that it's a little dated, but I believe the concept is still valid. You'll have to experiment some to make sure it works as expected.

For Word, I'm not normally a fan of Office interop/automation in a web app. But in this case you're not editing any documents: just loading it up long enough to print. And the fact that you're relying on another scarce resource (the printers) should keep this from scaling beyond what your web server could cope with. So you may have a rare case where Office automation in a web project makes sense.

like image 72
Joel Coehoorn Avatar answered Sep 23 '22 03:09

Joel Coehoorn