NiXPS
Tuesday, November 25, 2008
  Draw onto an XPS file
Here's another example of the capabilities of our new NiXPS SDK v2.6.

The NiXPS SDK v2.6 has the ability to do processing on existing XPS files. This means that you can modify, or in this case decorate, XPS files that are coming f.i. from a different source.
In this example I demonstrate how easy it is to get access to the content stream of an XPS page, and as an example draw a red square on the page.
This code could be a nice starting point for an application that would like to add a barcode, draw a watermark, etc...

So, to start off, we are going to process a given XPS file, and write the result out to another location (in C#):


public static void test_open_drawrectangle_save()
{
string pIn="../../examples/testfiles/Office2007_Powerpoint_Drawing_Fills_Texture.xps";
string pOut="../../examples/output/open_drawrectangle_save.xps";


Next, read the XPS file, and get a handler to the page, and page content.


NOPackage lPackage = NOPackage.readPackageFromFile(pIn);
// get first page
NOPage lPage = lPackage.getDocument(0).getPage(0);

// get content stream
NOXFixedPage lContent = lPage.getFixedPage();


Now, let's do some drawing. We add a path, with a square geometry and in a transparant red


// append a rectangle
// a rectangle is a path, we will add this in a seperate canvas (group)
// and we will put this canvas at the end of the stack, so it will be displayed on top
NOXPath lPath=lContent.createCanvas(lContent.getNumCanvas()).createPath(0);
lPath.intialize();

// geometry: (100,100)-(200,200)
lPath.setData("M 100,100 L 200,100 L 200,200 L 100,200 Z");

// color: ARGB - so full red, transparant overlay
lPath.setFill("#99FF0000");


That's about it. Now save and close:

// write the XPS file out
lPackage.writePackageToFile(pOut);

NOPackage.destroyPackage(ref lPackage);
}


The result is the input file, with a red, transparent square that lies over on the first page.
As the NiXPS SDK uses XPS natively, the only change you'll find in the file is that square, all the rest is exactly the smae as the input document.
 
Comments: Post a Comment

Subscribe to Post Comments [Atom]





<< 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]