Convert any File to XPS!
People have been asking about how to convert all sorts of formats to XPS and now we're pleased to announce there is a way to do so. All you need to do is install a printer driver and make one call to our library.
Any file format that can be printed by a program on your system will be able to generate an XPS file without any user interaction and our library will trigger the necessary calls to do so.
Let me explain what you need to do.
Our next version of the library comes with a printer driver. You need to install this printer driver on the system where you want to generate the XPS files. Download and unzip our library. In the Control Panel for your Printer you "Add a printer".
Add a local printer. When you get the following dialog:
choose to create a new local port for it. Pressing the Next button will prompt you for a suitable name. Choose something like "C:/NiXPS/output.xps"
The prompt appears to choose a printer driver.
Choose Have Disk... and when the dialog appears to insert the manufacturer's installation disk, click on Browse...
Now browse to the place where you just downloaded our library and in the folder driver choose the xdsmpl.inf file.
Click OK and Next and give the printer a name:
You can accept the default to not share the printer. Print a test page or skip that and just click Finish and you're all set:
What you have just done is install a printer driver like the (on Vista) preinstalled Microsoft XPS Document Writer that can print to XPS files. The difference however is that this one is mute. It won't come up and ask where to save the file and it won't open the XPS file afterward.
That way it can be used to generate XPS documents from whatever files are printable on your system. In other words if you have a file format you want to convert to XPS and you have an application that can print the file format you now have a solution to convert that format to XPS.
From our library all it takes is one call:
static public UInt32 convertToXPSViaPrinter(string pSourceFile,
You give it paths to the source file and the resulting destination file, you give it the location of the printers output file which is the one you set up while you were creating the local port and you give it the printer name you just installed. All of that and a timeout in seconds so that when things go horribly wrong your system does not hang. The method returns whether it was successful or not. There is an example that uses this in the sample project in the SDK.
That's it. It should work on Windows XP and Windows Vista, both for 32 and 64 bit applications.
Let us know what you think.