NiXPS
Tuesday, March 17, 2009
  Combine XPS documents: add header and footer


In a document workflow it is very common that different parts of a document come from separate sources.

The typical example is the document flow of invoices.
Generally invoices are generated by software that is tied to the accountancy department of a company. This invoice is then printed on company letterhead, and send out.

Ideally: to keep documents fully electronic, this last stage, combine invoice and letterhead, needs to be done in software. And both XPS and NiXPS can come to the rescue here.

First of all, getting an XPS version of an invoice out of your accounting software is very easy. With help of the free virtual XPS printer that is delivered with windows you can print from your software to an XPS file.
Of course, in a document flow invoice generation is much more automated. Chances are the accounting software can be customized to print, or even an integration with .NET is possible, so XPS can be generated on the fly.

Then combining this invoice with a company logo and a footer can be done with our upcoming NiXPS SDK v2.6.2 and the new function: copyPageOnTop().

Literally in a few lines of C# it is possible to combine any number of XPS pages, the NiXPS SDK takes care of the housekeeping needed to do this.

Let me walk you through an example for this; We have an invoice (invoice.xps) file, which we will combine with our company logo (logo.xps) and a footer (footer.xps).

First thing to do in the function: open up all our XPS files:

public static void Main(string[] args)
{
NOPackage lInvoice = NOPackage.readPackageFromFile("../testfiles/invoice.xps");
NOPackage lLogo = NOPackage.readPackageFromFile("../testfiles/logo.xps");
NOPackage lFooter = NOPackage.readPackageFromFile("../testfiles/footer.xps");


The logo.xps has the logo in page 1. Our invoice is also a one pager; So to combine them we will copy page 1 of the logo.xps on top of page 1 of invoice.xps.
This will return a handle to a NOXCanvas:

NOXCanvas lLogoCanvas=lInvoice.getDocument(0).getPage(0).copyPageOnTop(lLogo.getDocument(0).getPage(0));


This NOXCanvas is a handle to the content that was inserted.
This allows to do some customization: in this example we will apply a transformation matrix to scale the logo to 60%, and move it to position (30,30):

lLogoCanvas.setRenderTransform("0.6,0,0,0.6,30,30");


Same thing for the footer, copy page on top, and transform:

NOXCanvas lFooterCanvas = lInvoice.getDocument(0).getPage(0).copyPageOnTop(lFooter.getDocument(0).getPage(0));
lFooterCanvas.setRenderTransform("0.72,0,0,0.72,0,100");


Write out the file and clean-up:

lInvoice.writePackageToFile("../output/out.xps");

NOPackage.destroyPackage(ref lInvoice);
NOPackage.destroyPackage(ref lLogo);
NOPackage.destroyPackage(ref lFooter);
}


And that's it!

To download the SDK in trial: fill out this form, you'll receive a download link (and no spam).
 
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]