Create XpsDocument From NOPackage Using MemoryStream
A customer asked for a way to create an XpsDocument in .NET using the NiXPS Library. This is the code you need:
public static void test_XPSDocumentFromMemoryBuffer()
string pIn = "../../examples/testfiles/catalog.xps";
NOPackage lPackage = NOPackage.readPackageFromFile(pIn);
UInt32 lBufferSize = 1000 * 1000; // 1000 kb = 1M
byte lBuffer = new byte[lBufferSize];
uint lFileSize = 0;
lPackage.writePackageToBuffer(lBuffer, lBufferSize, ref lFileSize);
MemoryStream lStream = new MemoryStream(lBuffer, 0, (int)lFileSize);
string inMemoryPackageName = "memorystream://myXps.xps";
Uri packageUri = new Uri(inMemoryPackageName);
Package lXPSPackage = Package.Open(lStream);
//Add package to PackageStore
XpsDocument xpsDoc = new XpsDocument(lXPSPackage,
FixedDocumentSequence fixedDocumentSequence =
// Do operations on xpsDoc here
// Note: Please note that you must keep the Package object
// in PackageStore until you are completely done with it since
// certain operations on XpsDocument can trigger delayed
// resource loading from the package.
When you download our SDK
you can paste this test in. However you will need to change the threading model of the Main method to STAThread. You can do this by adding [STAThread] just before the Main method like so:
public static void Main(string args)
// ... rest of code
Hope this helps.
WPF visual to PDF - control page size
With our NiPDF library it is very easy to build PDF based on WPF visuals. It is literally a few lines of code which you can find documented on our website
This week I got the question from a customer who wanted to influence the page size.
This is fairly easy to do by means of the PrintTicket class.
In line with the example on our website, the second step becomes:
// STEP 2: Convert this WPF Visual to an XPS Document
MemoryStream lMemoryStream = new MemoryStream();
Package package = Package.Open(lMemoryStream, FileMode.Create);
XpsDocument doc = new XpsDocument(package);
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
//Create PrintTicket for document and set its page size to the proper custom page size
PrintTicket printTicket = new PrintTicket();
//Set the page size to a custom 3.5" x 2.5" page
printTicket.PageMediaSize = new PageMediaSize(3.5 * 96.0, 2.5 * 96.0);
Easy to do, provided you know how to do it - as always!
Experimental NiPDF.JS PDF Browser update
Give it try at http://nixps.com/nipdf/pdfbrowse.html
NiPDF.NET: update to text searching for PDF
A customer flagged that the PDFs generated with NiPDF weren't text searchable.
Previous versions of the NiPDF library didn't output the ToUnicode character mapping in the PDF, this has been fixed.
If you go to http://nipdf.com
and download the NiPDF SDK you will generate fully searchable PDFs!
The computer industry is in constant evolution.
One of the recent exciting developments is the fact that the web browser is becoming a lot more powerful than a few years back.
Chrome entered the browser landscape, Safari is going strong, Firefox as alternative browser is a big success, and Microsoft is catching up now with a massive technical leap in their upcoming Internet Explorer 9.
These recent, powerful changes are not about web pages
This is all about web applications
With the recent HTML5 developments, the browser is becoming a viable platform to host applications. Applications that do not need a server backend.
Think about it: in the very near future everyone will have access to a HTML5 browser.
This HTML5 browser will be able to run HTML5 applications, independent of the underlying platform.
This means no configuration management issues, and instant installation, as these apps can be server directly from a bog standard web server.
There are more advantages: scaling. A regular client-server application needs more power at the server, when the client base grows.
Pure in browser applications do not need a server for processing, pure elastic scaling, no additional investments server side.
And the extra beauty of it: a better use of the available processing power at the client, as in a lot of cases these system are very capable, but running idle.
You need a browser that supports the HTML5 FileReader object, so currently this means FireFox 3.6+ of Chrome 7.0 beta. Other are catching up soon.
Take a look at: http://nixps.com/nipdf/tools/pdfbrowse.html
It is experimental, but all your feedback is very welcome at email@example.com!
NiXPS launches NiPDF v1.0
After many months of work I'm pleased to announce a new product we are launching today: NiPDF v1.0.
This product is a direct result of our experiences with customers all over the world working in .NET and wanting to generate PDF.
We have learned that generating PDF in .NET is cumbersome and downright painful - and our aim is to put our technology to work to alleviate the pain and simplify this..NET front and center
A lot of PDF solutions out there are not really .NET.
They are a thin veil of .NET around a big body of native code.
Our NiXPS SDK has exactly the same architecture.
This works, and is often very efficient, but it kind of defeats the purpose of working with managed code.
Often there is a requirement to only work with managed code assemblies.
With our NiPDF v1.0 we introduce a 100% managed code library
.No native code dependency
NiPDF is a lean and mean, 100% native, PDF library that allows you to efficiently generate PDF in .NET.No special API to learn, no vendor lock-in
Another drag in today's PDF SDK's is the fact that in order to generate PDF, one needs to code against an API that the third party has defined.
This introduces a learning curve, and introduces vendor lock-in, as your code will depend on the third-party's API.
Thanks to our XPS heritage we are able to offer an innovative solution for this.
Via the .NET built-in ability to convert WPF visuals (and FixedDocuments) to XPS, you can code agains the default WPF API, and in 1-2-3
generate a PDF from this with a minumum of calls into our NiPDF library!High quality, keeping text and vectors intact
The NiPDF PDF output keeps text and vectors intact, resulting a small, high quality, fully searchable PDFs.NiPDF SDK and NiXPS Converter SDK, brothers in arms
NiPDF is premier choice for quick and easy PDF generation for .NET.
We continue to develop our NiXPS Converter SDK, which thanks to its native architecture, offers a better alternative for performance critical applications, has a more versatile feature set (f.i. PDF/A generation) and has supports C/C++ and OSX.
Take a look at the NiPDF product site at http://nipdf.com
and download the trial.
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