NiXPS
Friday, January 14, 2011
  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
    PackageStore.AddPackage(packageUri,lXPSPackage);

    XpsDocument xpsDoc = new XpsDocument(lXPSPackage,
				CompressionOption.Maximum,
				inMemoryPackageName);
    FixedDocumentSequence fixedDocumentSequence = 
				xpsDoc.GetFixedDocumentSequence();

    // 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.

    PackageStore.RemovePackage(packageUri);

    xpsDoc.Close();
}
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:
[STAThread]
public static void Main(string[] args)
{
	// ... rest of code
}
Hope this helps.
 
Friday, November 05, 2010
  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);
writer.Write(visual,printTicket);
doc.Close();
package.Close();
}


Easy to do, provided you know how to do it - as always!
 
Wednesday, October 27, 2010
  Experimental NiPDF.JS PDF Browser update
We have updated our client-side Javascript PDF browser. When it encounters a flate/zip stream, it will deflate it. And binary stuff is now presented in a much more useful way:



Give it try at http://nixps.com/nipdf/pdfbrowse.html.
 
Thursday, October 14, 2010
  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!
 
Tuesday, October 12, 2010
  PDF library in Client-Side Javascript - Adventures in Javascript
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.

So at NiXPS are a big believer in this, and we also think that software developers will start looking for tools and components for this new world. And for this we have started to support our software 100% natively in Javascript.

We are working on a 100% native Javascript NiPDF library, and as a demo we have build a tool that allows you to look structured at the innards of a PDF file.
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 info@nixps.com!

 
Tuesday, September 21, 2010
  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.
 
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);
 

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]