Printing from a Windows Service via Aspose.Words - splwow64 app crash

Hi,

We developed a Windows Service application and create an Aspose.Words Document and print via the Document.Print method. We build with a target platform of x86 and deploy to a 64 bit environment, printing to a printer using a 64 bit printer driver. We deploy to Windows Server 2008 R2. I’m currently testing the service on my PC running Windows 7 64 bit (Service Pack 1).

The splwow64.exe is crashing when printing from the service and we’re receiving the following error ‘The handle is invalid’:

30/03/2011 10:13:45 AM [00007] Err: System.ComponentModel.**Win32Exception: The handle is invalid**
at System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at Aspose.Words.Document.Print(PrinterSettings printerSettings, String documentName)
at Aspose.Words.Document.Print(PrinterSettings printerSettings)
at HSL.Documents.DocumentManager.Print(String inputFile, String printerName, Int32 duplexMode, Int32 firstTray, Int32 followerTray, Boolean hasAttachments) in D:\Projects\01 Components\10.01 Sandboxes\CR3617\HSL.Documents\Source\DocumentManager.cs:line 180

Event Viewer, Windows Logs, Application:

Fault bucket , type 0
Event Name: APPCRASH
Response: Not available
Cab Id: 0
Problem signature:
P1: splwow64.exe
P2: 6.1.7601.17514
P3: 4ce7b4c8
P4: fx6raeim.dll
P5: 0.3.0.0
P6: 4a95e9d3
P7: c0000005
P8: 000000000006771d
P9: 
P10: 
Attached files:
These files may be available here:
C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_splwow64.exe_fd25137322879283daa71fcceecd10aa2d4399_09f5e679
Analysis symbol: 
Rechecking for solution: 0
Report Id: 15a5dda9-5f51-11e0-829d-0025b30a1e17
Report Status: 4

I’ve seen a few Aspose.Words posts about whether it prints using System.Drawing.Printing and .NET issues related to printing from a service. I’ve also reviewed the Aspose.Words Product Documentation, ‘How-to: Print a Document on a Server via the XpsPrint API’, (https://docs.aspose.com/words/net/print-a-document-programmatically-or-using-dialogs/) and tried implementing the XpsPrintHelper class to attempt to resolve this issue, but receive the error:

‘The data area passed to a system call is too small’

which I’ve seen documented in post 206818. After adding debugging messages, it appears the exception is generated in XpsPrintHelper.StartJob after the result of the call to StartXpsPrintJob is != 0.

private static void StartJob(string printerName, string jobName, IntPtr completionEvent, out IXpsPrintJob job, out IXpsPrintJobStream jobStream, TextWriter writeFile)
{
    int result = StartXpsPrintJob(printerName, jobName, null, IntPtr.Zero, completionEvent,
    null, 0, out job, out jobStream, IntPtr.Zero);

    writeFile.WriteLine("after calc result (StartJob)");

    if (result != 0)
    {
        writeFile.WriteLine("result != 0, (StartJob), throw Win32Exception");
        throw new Win32Exception(result);
    }
}

So I’m wondering if Aspose.Words supports printing from a Windows Service and if you could provide any assistance on how we can print from a Windows Service using Aspose.Words?

Thanks,

Matt

Hi Matt,
Thanks for your request. If problem occurs only upon printing, then I think it is not a problem in Aspose.Words. Probably the problem is more general.
Please make sure that you can print in server environment. You can try using the following code for testing. 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(@"C:\Temp\test.jpg"), e.MarginBounds.Left, 
   e.MarginBounds.Top);
}

This code just prints an image.
Also, have you tried printing from a console or windows application for example? Does it make any difference?
Best regards.