Unable to print word document through Network Printer from the server

Hi,

I have a requirement to send a print from the web application deployed on one of the servers. The printer is not installed on the server and is a network printer.

This works when I try sending print from my local machine. When the same code is deployed to the server, it doesn’t work. I tried using a test console application as well and its not working with Aspose.Print.

Please suggest.

Thanks,
Sulabh

Hi Sulabh,

Thanks for your inquiry. Please note that the Aspose.Words Print method uses System.Drawing and standard .NET printing classes. You need to install the printer before printing the documents.

Please try following code snippet for testing at your end. This code does not use Aspose.Words at all. So if it will not work, the problem is somewhere on your side. This code just prints an image. Please let us know if you have any more queries.

PrintDocument doc = new PrintDocument();
doc.PrinterSettings.PrinterName = @"\192.168.0.2\hp LaserJet 1010 Series Driver";
doc.PrintPage += Doc_PrintPage;
doc.Print();

============================================================================

private void Doc_PrintPage(object sender, PrintPageEventArgs e)
{
   e.Graphics.DrawImage(Image.FromFile(@"Common\test.jpg"), e.MarginBounds.Left, 
   e.MarginBounds.Top);
}

Thanks for the reply.

I have follow up points:

  1. I cannot install the network printer onto the PRODUCTION server as its not allowed by our operations team.
  2. The code snippet that you shared works fine for image files (jpeg etc). However, I am trying to print word/excel documents.

Can you please share the sample code to print a word/excel document from the server to a network printer?

Thanks,
Sulabh

Hi Sulabh,

Thanks for your inquiry. Please use Document.Print method (String) to print the whole Word document to the specified printer, using the standard (no User Interface) print controller. Please check following code example.

Document doc = new Document(MyDir + "Document.doc");
doc.Print("KONICA MINOLTA magicolor 2400W");

Please read following article about printing Excel documents. Hope this helps you.
Specify Job or Document Name while printing with Aspose.Cells