views:

200

answers:

2

I have a webpage that activates a print job on a printer. This works in the localhost environment but does not work when the application is deployed to the webserver. I'm using the PrintDocument class from the .net System.Drawing.Print namespace. I'm now assuming the printer has to be available to the application on the remote server? Any suggestions on how I would get this to work?

PrintDocument pd = new PrintDocument();
PaperSource ps = new PaperSource();
pd.DefaultPageSettings.PaperSize = 
    new System.Drawing.Printing.PaperSize("Custom", 1180, 850);
pd.PrintPage += new PrintPageEventHandler
                    (this.pd_PrintPage);

// Set your printer's name.  Obtain from
// System's Printer Dialog Box. 
pd.PrinterSettings.PrinterName =
    "Okidata ML 321 Turbo/D (IBM)";


//PrintPreviewDialog dlgPrintPvw = new PrintPreviewDialog();
//dlgPrintPvw.Document = pd;
//dlgPrintPvw.Focus();
//dlgPrintPvw.ShowDialog(); 

pd.Print();
+5  A: 

The printer is on a different computer. PrintDocument is for use in desktop applications, not web applications.

To print on the client, you would need to use JavaScript, and you would only be able to print documents already on the client machine. I don't know for sure that there is a way to print on the client. You may be able to display a "Print" dialog and have the user print the file himself.

John Saunders
Further limited than printing "documents already on the client machine" I do believe he'd only be able to print HIS pages, using window.print(); . I don't think javascript could reach out and print any old document on his computer, as this would completely break the sand-boxing model of most browsers.
eidylon
How would an intranet application print to a local printer? That possible?
FiveTools
What about embedding a Windows Form Control in an asp.net page or using Silverlight?
FiveTools
@FiveTools: a Windows Forms control or ActiveX control would work in an intranet and not on the Internet. I don't know if Silverlight can print.
John Saunders
A: 

Silverlight 4 can print. However, it is restricted to print only 1 page properly, if one enables the HasMorePages argument, it goes crazy and fills the printing job with endless documents... I am currently trying to figure out why is that. Here

gabore