docexample_nocontentstream.cpp

00001 #include "NOPackage.h"
00002 #include "NOPage.h"
00003 #include "NOContentStreamNavigator.h"
00004 
00005 using namespace NiXPSObjects;
00006 
00007 // this examples overlays page 1 of document 1 with page 1 of document 1 of another XPS package
00008 void overlayPage(const UTF8Char *baseXPSdoc, const UTF8Char *overlayXPSdoc, const UTF8Char *pOut)
00009 {
00010         // start
00011         NOPackage *basePackage, *overlayPackage;
00012         NOPage basePage, overlayPage;
00013 
00014         // read base doc, get handler to page in question
00015         basePackage = NOPackage::readPackageFromFile(baseXPSdoc);
00016         basePage = basePackage->getDocument(0).getPage(0);
00017 
00018         // read overlay doc, get handler to page in question
00019         overlayPackage = NOPackage::readPackageFromFile(overlayXPSdoc);
00020         overlayPage=overlayPackage->getDocument(0).getPage(0);
00021 
00022         // get a content stream navigator in the basePage, navigate to the 'FixedPage'
00023         NOContentStreamNavigator mergedNav=basePage.getContentStreamNavigator();
00024         mergedNav.toChild("FixedPage");
00025 
00026         // inject some xml prefix
00027         mergedNav.insertAsChild("<!-- some prefix xml code -->");
00028 
00029         // get a content stream navigator in the overlayPage, navigate to the 'FixedPage'
00030         NOContentStreamNavigator overlayNav=overlayPage.getContentStreamNavigator();
00031         overlayNav.toChild("FixedPage");
00032 
00033         // insert in the overlayNav childs into the merged page
00034         for (UInt32 lCount=0; lCount<overlayNav.getNumberOfChilds(); lCount++)
00035         {
00036                 NOContentStreamNavigator lNav=overlayNav;
00037                 lNav.toChild(lCount);
00038                 mergedNav.insertAsChild(lNav);
00039         }
00040         
00041         // inject some xml postfix
00042         mergedNav.insertAsChild("<!-- some postfix xml code -->");
00043                 
00044         // So now document 0 has some page 0...
00045 
00046         // copy over the resources
00047         basePackage->getDocument(0).getPage(0).copyResourcesFrom(overlayPage);
00048         
00049         // normalize page content (so the URL's point to correct resources)
00050         basePage.normalizeContentStream();
00051                 
00052         basePackage->writePackageToFile(pOut);
00053 
00054         // clean-up
00055         NOPackage::destroyPackage(overlayPackage);
00056         NOPackage::destroyPackage(basePackage);
00057 }

Generated on Thu Jul 3 15:30:32 2008 for NiXPS Library SDK by  doxygen 1.5.3