We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Problem with XpsPrintHelper

Hello,

I have a problem with the XpsPrintHelper. I’m running a Windows services on Windows 2012 R2.
This service print Word documents using Aspose Words and the XpsPrintHelper.
I get the following exception:

System.ComponentModel.Win32Exception (0x80004005): The operation attempted is not supported
at Common.PrintService.Print.XpsPrintHelper.CheckJobStatus(IXpsPrintJob job) in D:\trunk\Common\source\Common.PrintService\Print\XpsPrintHelper.cs:line 159
at Common.PrintService.Print.XpsPrintHelper.Print(Stream stream, String printerName, String jobName, Boolean isWait) in D:\trunk\Common\source\Common.PrintService\Print\XpsPrintHelper.cs:line 86
at Common.PrintService.Print.XpsPrintHelper.Print(Document document, String printerName, String jobName, Boolean isWait) in D:\trunk\Common\source\Common.PrintService\Print\XpsPrintHelper.cs:line 47

I don’t know what is wrong because it is working fine on my development environment which is a Window 7 Ultimate machine running exactly the same printer drivers as the Windows 2012 R2 server.

This is the call to the XpsPrintHelper:

XpsPrintHelper.Print(doc, printJob.Batch.Driver.DriverName, "Print service PrintJobID " + printJob.ID, true);

It is running fine when I use doc.Print(printJob.Batch.Driver.DriverName); but sometimes I get strange results that is why I use XpsPrintHelper like you suggest when using a Windows service.

Hi Ron,

Thanks for your inquiry.

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 = @"\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);
}

This code just prints an image. Moreover, please try the Document.Print method in simple console application at Windows 2012 R2 and let us know about your findings.