NiXPS
Thursday, July 08, 2010
  Example: create XPS and add hyperlink using NiXPS SDK
A customer asked me for a code sample to illustrate the creation of an XPS document, and the ability to make content link to a hyperlink.

It might be of interst to others, so I am posting it on the blog.
This sample works with NiXPS SDK 2.6.6, and uses .NET.

First: create an XPS package with a document:


NOPackage lPackage=NOPackage.createPackage(1,"out.xps");


Now: create a page and add content using the document model.
We do this by getting the root FixedPage, create a Canvas inside, and store a Glyphs element which can hold a string of text.


{
NOPage lPage=lPackage.getDocument(0).createPage();
NOXFixedPage lContent=lPage.getFixedPage();
lContent.intialize(8.3*96,11.7*96); // A4: 210x297mm or 8.3x11.7inch
NOXCanvas lCanvas=lContent.createCanvas(0);
lCanvas.intialize();
NOXGlyphs lGlyphs=lCanvas.createGlyphs(0);


We also need to create and supply a NOFont to be used. We load this up from disk, where we have stored Arial.ttf, an opentype font we would like to use.
We then fill the Glyphs.


NOFont lFont=lPage.addFont("../testfiles/Arial.ttf");
NOString lURI = new NOString("/" + lFont.getPartName());
lGlyphs.intialize(20, lURI.getHandler(), 300, 50);
lGlyphs.setFill(new NOString("#FF000000").getHandler());
lGlyphs.setUnicodeString(new NOString("Take me to http://nixps.com").getHandler());


Next: the link. We name the Glyphs, and add a NavigateURI attribute which gives us the intented behaviour to link to a website.


lGlyphs.setName(new NOString("page_1").getHandler());
lGlyphs.setFixedPageNavigateUri(new NOString("http://www.nixps.com").getHandler());
}


Now we're done. So all left is to write out the file and clean-up.

// write out and close
lPackage.writePackageToFile("out.xps");
NOPackage.destroyPackage(ref lPackage);
 
Comments: 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]