It is possible also to use print queue to print to the XPS document writer but it will always show the file dialog.
See below other alternatives to convert and print to XPS file.
Programmatically converting files to XPS
This is not as simple as you wish many users out there have tried and there is many different ways to accomplish it all which arent the best.
One way (easiest way) to convert documents to XPS would be to use WORD 2007+ API to do it. See below a snipped from this MSDN forum question
To programmatically convert docx to xps using Word 2007 see Document.ExportAsFixedFormat in the Word Object Model Reference (http://msdn2.microsoft.com/en-us/library/Bb256835.aspx). However, since this is a server-side scenario you should take note of KB 257757 Considerations for server-side Automation of Office (see http://support.microsoft.com/kb/257757).
Printing Images to XPS
You can easily print an Image to XPS file using the code below. The code below is WPF example the image you pass into the write method needs to be wrapped in a canvas see this post for an example: http://denisvuyka.wordpress.com/2007/12/03/wpf-diagramming-saving-you-canvas-to-image-xps-document-or-raw-xaml/
XpsDocument xpsd = new XpsDocument("C:\\YourXPSFileName.xps", FileAccess.ReadWrite);
System.Windows.Xps.XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(xpsd);
xw.Write(YourImageYouWishToWrite);
See an extended example below:
public void Export(Uri path, Canvas surface)
{
if (path == null) return;
// Save current canvas transorm
Transform transform = surface.LayoutTransform;
// Temporarily reset the layout transform before saving
surface.LayoutTransform = null;
// Get the size of the canvas
Size size = new Size(surface.Width, surface.Height);
// Measure and arrange elements
surface.Measure(size);
surface.Arrange(new Rect(size));
// Open new package
Package package = Package.Open(path.LocalPath, FileMode.Create);
// Create new xps document based on the package opened
XpsDocument doc = new XpsDocument(package);
// Create an instance of XpsDocumentWriter for the document
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
// Write the canvas (as Visual) to the document
writer.Write(surface);
// Close document
doc.Close();
// Close package
package.Close();
// Restore previously saved layout
surface.LayoutTransform = transform;
}
There are third party tools that allow you to print PDFs and other file formats to XPS.
Printing XPS files
It is possible to print XPS Documents programmatically You will need .Net 4 at least for this solution.
The example below uses the Print dialog from WPF and some of the classes from System.Windows.Xps and System.Printing.
The code below will print the Xps file to the default printer on the system however if you want to print to a different printer or even print to a print server you need to change the PrintQueue object on the print dialog.
Which is quite simple using the System.Printing namespace.
See the example below.
Please bear in mind that because it is using the WPF dialog it needs to run on a STATThread model.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Printing;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Xps.Packaging;
namespace ConsoleApplication
{
class Program
{
[STAThread]
static void Main(string[] args)
{
PrintDialog dlg = new PrintDialog();
XpsDocument xpsDoc = new XpsDocument(@"C:\DATA\personal\go\test.xps", System.IO.FileAccess.Read);
dlg.PrintDocument(xpsDoc.GetFixedDocumentSequence().DocumentPaginator, "Document title");
}
}
}
See below some Helpful links.
- Xps Document documentation
- Print Dialog from WPF documentation
- System.Printing namespace documentation
Hope this helps and fit your needs