I'm aware similar questions have been asked in the past, but they seem to be from circa five years ago, and was wondering if there is any more information on this.
I have the following code, which works well when ran as a desktop application:
var printServer = new PrintServer();
var printerQueues = printServer.GetPrintQueues();
var printer = printerQueues.FirstOrDefault(x => x.Name.Equals(sPrinter));
if (printer != null)
{
try
{
printer.AddJob("Printing test file", sLoc, false);
printJobSuccess = true;
}
catch (Exception)
{
// Log print fail
}
}
However, when I build it into a windows service it doesn't run. Similar to this question (Xps printing from windows service) I have also tried Aspose, but that doesn't work either.
I've also tried printing using Aspose.Words and the XpsPrint API (see: http://www.aspose.com/docs/display/wordsnet/How+to++Print+a+Document+on+a+Server+via+the+XpsPrint+API) - updated Nov 14, 2015 and suggests a way around printing XPS files for Windows Service applications. See below:
using (Stream stream = new FileStream(sLoc, FileMode.Open, FileAccess.Read))
{
XpsPrintHelper.Print(stream, sPrinter, "Printing test file", true);
}
I've seen a lot of people comment saying they're still looking for a solution to this. Has anyone achieved it or know of a workaround / way of doing so? Or am I doing something wrong?