Free Support Forum -

Printing from an ASP.NET page


I am trying to do a simple print from a webpage, i have added the reg hack to allow access to the printer and am using impersonation however i always get the following error:

[IndexOutOfRangeException: Index was outside the bounds of the array.]
System.Drawing.Printing.PaperSizeCollection.get_Item(Int32 index) +37
Aspose.Words.Rendering.PrinterSettingsContainer…ctor(PrinterSettings settings) +119
Aspose.Words.Rendering.AsposeWordsPrintDocument.xcb9cc4ea05847956() +213
System.Drawing.Printing.PrintController.Print(PrintDocument document) +208
System.Drawing.Printing.PrintDocument.Print() +186
My code is very simple:

Document doc = new Document(@“C:\test.doc”);
using (new Impersonator(“username”, “domain”, “password”))
PrinterSettings pr = new PrinterSettings();
pr.PrinterName = ConfigurationManager.AppSettings[“Printer”].ToString();

Please help !

Thank you
Hi Chris,

Thanks for your inquiry. In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v13.4.0) from here and let us know how it goes on your side. If the problem still remains, please attach your input Word document here for testing. I will investigate the issue on my side and provide you more information.

Moreover, please note that the Aspose.Words Print method uses System.Drawing and standard .NET printing classes. 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.

PrintDocument doc = new PrintDocument();

doc.PrinterSettings.PrinterName = @"\\\hp LaserJet 1010 Series Driver";

doc.PrintPage += Doc_PrintPage;



private void Doc_PrintPage(object sender, PrintPageEventArgs e)


e.Graphics.DrawImage(Image.FromFile(@"Common\test.jpg"), e.MarginBounds.Left, e.MarginBounds.Top);