XPS Printing from Service


#1

I am attempting to print Word documents that have been created by Aspose.Words in a service environment.


I am using the XPSPrintHelper code you have published in your docs and online. My problem is that my documents print perfectly when the code is running inside an interactive process (with a logged-on user session), but when printing from a Windows Service (or a service hosted in IIS) the documents come out with nothing but garbage characters.

I have reproduced this problem on both Windows Server 2008 R2 and on Win 7 64, and on 2 different Lexmark printers. It does not appear to matter what text is in the document – even a very simple 1 paragraph document will reproduce the problem.

I am using version 10.3 of Aspose.Words (though the problem was evident in earlier versions also).

I have an extremely simple Windows Service solution that repros it if that would help you.



#2

Hi Bruce,

Thanks for your request. Probably the problem occurs because when you use Aspose.Words in service, Aspose.Words does not have right to read fonts in your system.

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/how-aspose-words-uses-true-type-fonts.html

Best regards,


#3

So I copied all the font files from my C:\Windows\Fonts folder into a folder I confirmed my service has access to and then called FontSettings.SetFontFolder() with that folder. Did not change the outcome.


I don’t think that’s the problem anyway because on my development machine I have the service logging in under my own account.

Other suggestions?

#4

Hi

Thank you for additional information. Could you please attach your input and output(XPS) documents here for testing? We will investigate the problem and provide you more information.

Best regards,


#5

Document is attached, but I don’t think it really matters. I have not been able to get ANY document to print successfully from a service.


Also, I do not have an output document – I am just printing directly from an Aspose.Words document using this method of XpsPrintHelper:

public static void Print(Aspose.Words.Document document, string printerName, string jobName, bool isWait)

The only other thing that might be relevant is that we only have Lexmark printers at our workplace so I have not been able to test on any other brand of printer. However I have tried on two different Lexmark printers with identical results.


#6

Hi

Thank you for additional information. If you are using code provided in the following article to print the document:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-print-a-document-on-a-server-via-the-xpsprint-api.html

You can see that internally Aspose.Words is used to convert the document to XPS and then XpsPrint API is used to print XPS document. So you can simply try converting your document to XPS in the mentioned environment to see whether the problem occurs on stage of converting document to XPS or upon print using XpsPrint API.

Best regards,


#7

The XPS document saves to a file from inside the service with no problems, so the bug only shows up when trying to print.


Are you able to reproduce this problem, or am I the only one seeing it?

#8

Hi

Thank you for additional information. No, I was unable to reproduce the problem on my side. Could you please attach XPS document produced on your side here for testing? I will check it and provide you more information.

Best regards,


#9

I attached a zip file that contains my simple Windows Service solution that reproduces the problem.


The XPS file and the original DOCX are also included in the zip.

I have reproduced the problem on several machines – I have not gotten it to work on a single machine. However, all the printers in our office are made by Lexmark. I wonder if it might be something with their drivers?

Were you able to print to a Lexmark printer?


#10

Hi Bruce,

Thanks for your request. I investigated the problem on my side and concluded that Aspose.Words does its work properly. i.e. Aspose.Words produces a valid XPS document. But XPS print API seems does not work properly in Windows Services. For testing purposes, I tried converting a document to XPS using MS Word and then print this XPS using XPS print API from service and the result is the same as yours.

I think, you should contact Microsoft support, maybe they will be able to help to resolve this strange problem.

I found the same problem posted on stackoverflow:

http://stackoverflow.com/questions/6123507/xps-printing-from-windows-service

Best regards,