Reputation: 381
This is a two-part question:
1.
The original .NET print classes (in System.Drawing.Printing) are not supported on the server side. (See http://msdn.microsoft.com/en-us/library/system.drawing.printing(VS.80).aspx )
I think that the newer XPS-based printing classes (in System.Printing) are supported on the server side, e.g. in ASP.NET apps and Windows Services, but I can't prove it. And Microsoft have not answered my questions about it.
Does anyone here know?
2
The new XPS-based printing will sometimes do an internal conversion to GDI. That is for cases where the only driver available is an old-style driver, even though the app is printing with the new printing classes. See http://msdn.microsoft.com/en-us/library/ms742418.aspx . Are the new classes safe for server-side use in that situation?
To clarify - this is entirely about the server printing stuff. For the purposes of this discussion, there is no web browser involved at all. A server, either windows service or asp.net, needs to directly print out a document, on a printer that is attached to the server.
Thanks.
Upvotes: 1
Views: 3448
Reputation: 1222
I don't think you need any of these ASPnose APIs.
There is sample code to do exactly this here:
https://groups.google.com/forum/?fromgroups#!msg/pdfnet-sdk/fOuGOvx06Tk/EckAX-ga2i8J
Upvotes: -1
Reputation: 381
As noted in my comment below, there is no supported solution for server-side printing in pure managed code.
But, Aspose have just released some code that lets you print XPS documents from managed code (successfully using PInvoke to call the XPS Print API). [For the record, I believe that Microsoft's intitial recommendation against using PInvoke to call XPS print was simply because it is a difficult API to interact with using PInvoke. But Aspose seem to have succeeded, which is good news, since it removes the need to involve separate any separate unmanaged DLL.]
All in all, the Aspose solution looks like the easiest fully-supported way to print complex documents from ASP.NET and Windows services.
Upvotes: 4
Reputation:
In .Net XPS support is part of WPF. The use of WPF in Windows services is unsupported (see MSDN) and therefore XPS printing with .Net, including use of System.Printing, is also unsupported for services.
The same answer applies for the 'conversion to GDI' part of the question since that process happens automatically (in the case that XPS content is being printed to a PrintQueue where the driver is not XPS, the framework automatically converts XPS content to the DDI calls expected by the driver if a GDI-based app were printing).
For server-side development (services) where XPS printing is required there are Win32 APIs available in Windows 7. Specifically, see the XPSPrint API which provides access to the XPS Print Path and supports automatic conversion for non-XPS print queues as well as the APIs available for maniplulating XPS content and working with print tickets.
Upvotes: 0
Reputation: 415735
If you're trying to get the user's browser to print from server code, forget it. The best you should hope for is to send a page to the browser with some javascript code that calls window.print()
.
Upvotes: -1