NiXPS
Wednesday, September 30, 2009
  XPS Imposition
I've written a small example script for NiXPS View v3.0 that implements XPS imposition.

Given a multipage file, it imposes 2 pages on 1 landscape A4 - so a 16 page document will yield an 8 page document, where each page has 2 pages on it.

The script is fairly simple, about 50 lines of code:

First, define our A4 paper size:

// paper size, use A4
lMaxWidth=1056;
lMaxHeight=816;


Then create a new XPS file:

// create a new XPS file, with a single document
lNewXPS=new NOPackage();
lNewXPS=lNewXPS.create(true,"spreads.xps");
lNewDoc=lNewXPS.getDocument(0);


Next, we walk over all the pages is the currently active document, and put 2 pages on each page. We do some RenderTransform magic to position the pages correctly:

// get the doc
lDocument=App.getDocument();
lNumberOfPages=lDocument.getNumberOfPages();

for (i=0; i<lNumberOfPages; i++)
{
if (i % 2==0)
{
// create a new page
lNewPage=lNewDoc.createPage();
lNewFixedPage=lNewPage.getFixedPage();
lNewFixedPage.setWidth(lMaxWidth);
lNewFixedPage.setHeight(lMaxHeight);
lOffsetX=0;
lNum=0;
} else
{
lOffsetX=lMaxWidth/2;
lNum=1;
}
// access the page
lPage=lDocument.getPage(i);
lFixedPage=lPage.getFixedPage();
lPageWidth=lFixedPage.getWidth();
lPageHeight=lFixedPage.getHeight();

// calculate the factor
lFactorWidth=(lMaxWidth/2)/lPageWidth;
lFactorHeight=lMaxHeight/lPageHeight;
lFactor=lFactorWidth;
if (lFactorHeight<lFactor)
lFactor=lFactorHeight;

// copy page on top
lNewPage.copyPageOnTop(lPage);
lCanvas=lNewFixedPage.getCanvas(lNum);
lCanvas.setRenderTransform(lFactor+",0,0,"+lFactor+","+lOffsetX+",0");
}


And that's it. Only thing left to do now at this point is give the newly created XPS file to the application, so the user can work with it further.

App.addPackage(lNewXPS);


As you can see you can fairly easy leverage the NiXPS SDK in Javascript this way. It's great for tools and customizations, and also for experimenting, as it is also fairly easy to convert this script to a C-Sharp or C++ source, and use it in conjunction with our SDK.

You can download the script, and find more on scripting on http://nixps.com/scripting
You can read more about our NiXPS SDK here
 
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]