Reputation: 6030
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();
Upvotes: 3
Views: 4891
Reputation: 1
I was having the same issues. I was told to put your code inside of this:
using (WindowsIdentity.GetCurrent().Impersonate())
{
// code here
}
It allows for specific user settings to be used instead of the ASP.NET settings for that particular printer.
This code got it to the printer, but now I'M having issues with multiple copies of one webform hitting the printer.
Upvotes: 0
Reputation: 161773
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.
Upvotes: 5