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:
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.
lContent.intialize(8.3*96,11.7*96); // A4: 210x297mm or 8.3x11.7inch
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.
NOString lURI = new NOString("/" + lFont.getPartName());
lGlyphs.intialize(20, lURI.getHandler(), 300, 50);
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.
Now we're done. So all left is to write out the file and clean-up.
// write out and close
XAML with databinding to PDF with NiXPS
A lot of customers ask me how they can go from XAML with databinding to PDF.
Our SDK can be a great part of a solution for this, if you go over XPS.
Here is a great article
that outlines how you can go from XAML with databinding to XPS with WPF.