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

Free Support Forum - aspose.com

Using XpsPrintHelper within a Windows Server 2012 R2 hosted service

Hello ASPOSE team!

I have reviewed https://docs.aspose.com/words/net/print-a-document-programmatically-or-using-dialogs/ and coded a Windows application using the recommended approach described under heading “Print a Document on a Server Code”. This works when I run the app on Windows Server 2012 R2.

Next, I got more ambitious and using that same technique, ran the same code from within a Windows Service, (running as me, with my own credentials). It finds the printer, but raises an error "

-2147467259 The operation attempted is not supported.

Question: Is there a specific platform update for Windows Server 2012 R2 that will enable XPS Printing from within a service? Can you offer any suggestions regarding XPS Printing using the XpsPrintHelper class from within a service?

Please advise. Thank you.

Hi Karl,

Thanks for your inquiry. Please check following link.

https://docs.microsoft.com/en-us/windows/win32/printdocs/xps-printing

We had already logged an issue (WORDSNET-10256) in our issue tracking system for our product team to investigate if Print Document Package API will be supported by Aspose.Words in future. We will further look into the details of this problem and keep you updated via this thread on the status of this issue. We apologize for any inconvenience.

You can use XpsPrint sample without any installation at Windows Server 2012. The same code of XPS Print API should work for Windows Service. Could you please share complete stack trace here for our reference? We will then provide you more information on this.

Thank you Tahir for the quick response and the link to the Print Document Package documentation. Sadly, the scope of the Print Document Package is Windows desktop, so it isn’t relevant to printing from within a Windows service.

I understand that I can use the XpsPrint sample without Server 2012R2, but since my client wishes it to run unattended on Windows Server 2012 R2, that option is off the table. However, if there is a legacy printing patch available for Windows Server 2012R2, that would be of great interest. I read that there was a legacy printing patch for Windows Server 2008. Refer to KB971512.

I wish the Aspose XpsPrint sample did work as a service on Server 2012R2. I could send you my code, but it is nothing extraordinary, just a class that wraps the XpsPrintHelper. As I mentioned, it works running within a desktop app on Server 2012R2, but not from within a service. Since a hosting service needs to run in the context of a user account (to have access to installed printers) code alone will not fully represent my usage case.

Although I can’t submit my entire environment, I will share that the service is running in the context of my account and that it does in-fact find the installed network printer and when it prints, it throws error -2147467259 “The operation attempted is not supported”. Here is the stack trace:

================================ 2016-08-30_08:27:38_784
Error -2147467259 occurred in ProcessQueuedTasks
Source: DirectPrinter
Message: The operation attempted is not supported
Stack Trace: at XpsPrint.XpsPrintHelper.CheckJobStatus(IXpsPrintJob job) in C:\Source\DirectToPrinter\ExsDirect2Printer\ExsDirect2Printer\XpsPrintHelper.cs:line 159
at XpsPrint.XpsPrintHelper.Print(Stream stream, String printerName, String jobName, Boolean isWait) in C:\Source\DirectToPrinter\ExsDirect2Printer\ExsDirect2Printer\XpsPrintHelper.cs:line 86
at XpsPrint.XpsPrintHelper.Print(Document document, String printerName, String jobName, Boolean isWait) in C:\Source\DirectToPrinter\ExsDirect2Printer\ExsDirect2Printer\XpsPrintHelper.cs:line 47
at ExsDirect2Printer.DirectPrinter.ProcessDirectPrintTask(String dpPrinter, String dpDocument) in C:\Source\DirectToPrinter\ExsDirect2Printer\ExsDirect2Printer\DirectPrinter.cs:line 157
at ExsDirect2Printer.DirectPrinter.ProcessQueuedTasks() in C:\Source\DirectToPrinter\ExsDirect2Printer\ExsDirect2Printer\DirectPrinter.cs:line 87

Hi Karl,

Thanks for sharing the stack trace. It seems that this issue is not related to Aspose.Words. The same code of XPS Print API should work using Windows Service. Perhaps, there are some user access rights issue at your end.

Sorry. “The operation attempted is not supported” is not raised for user account access issues.

The error occurred in CheckJobStatus(IXpsPrintJob job), which is in Aspose’s XpsPrintHelper.

The API function “CheckJobStatus” has been deprecated and is no longer supported in Server 2012 R2 except from within a desktop application.

Please join me and fellow Aspose user John Rusk in voting to reverse the deprecation of the XPS Print API.

Hi Karl,

Thanks for sharing the detail. We basically need to write a new module that will use Windows XPS Document API and Document Print API together to create an XPS document and print it. We will update you via this forum thread once this feature (WORDSNET-10256) available. We apologize for any inconvenience.

KarlSoCal:

Please join me and fellow Aspose user John Rusk in voting to reverse the deprecation of the XPS Print API.

We will vote for this.

A post was split to a new topic: Support XPS Print Document Package API

A post was split to a new topic: Jamesalex