NiXPS
Monday, December 15, 2008
  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,
string pDestinationFile,
string pPrinterOutputFile,
string pXPSPrinterDriverName,
UInt32 pTimeOut)

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.
kristof
 
Comments:
Can you send it a memory stream instead of a file?

And optionally can yout output a memory stream?
 
An external application needs access to the data, so it needs to be stored on disk.
However, this could be stored temporary, and we could help you with this.
Contact me at info@nixps.com for this.
 
Post a Comment

Subscribe to Post Comments [Atom]



Links to this post:

Create a Link



<< Home

Archives
September 2006 / October 2006 / November 2006 / December 2006 / January 2007 / February 2007 / March 2007 / April 2007 / May 2007 / June 2007 / July 2007 / August 2007 / September 2007 / October 2007 / November 2007 / December 2007 / January 2008 / February 2008 / March 2008 / April 2008 / May 2008 / June 2008 / July 2008 / August 2008 / September 2008 / October 2008 / November 2008 / December 2008 / January 2009 / February 2009 / March 2009 / April 2009 / May 2009 / June 2009 / July 2009 / August 2009 / September 2009 / October 2009 / November 2009 / December 2009 / January 2010 / February 2010 / March 2010 / April 2010 / May 2010 / June 2010 / July 2010 / September 2010 / October 2010 / November 2010 / January 2011 /

NiXPS home
XPS info from the creators
    follow me on Twitter
    Add to Technorati Favorites

    Subscribe to
    Posts [Atom]