docexample_contentstream.cpp

00001 #include "NOPage.h"
00002 #include "NOPackage.h"
00003 
00004 using namespace NiXPSObjects;
00005 
00006 void manipulateContentStream()
00007 {
00008         NOPackage *lPackage = NOPackage::readPackageFromFile("CoreProperty2.xps");
00009 
00010         // get a handler to the first page of the first out source package
00011         NOPage lPage = lPackage->getDocument(0).getPage(0);             
00012 
00013         // get the stream of this page
00014         UInt32 lPageContentLength = lPage.getContentStreamLength();
00015         UTF8Char *lPageContent = new UTF8Char[lPageContentLength + 1];
00016         lPage.getContentStream(lPageContent,lPageContentLength+1);
00017 
00018         std::string lNewXML;
00019         lNewXML = "<Glyphs Name=\"a3\" BidiLevel=\"0\" Fill=\"#FF000000\" "
00020                          "FontUri=\"/Documents/1/Resources/Fonts/301E55E6-2E6C-620E-337B-92143D57576B.odttf\" FontRenderingEmSize=\"11.04\" "
00021                          "StyleSimulations=\"None\" OriginX=\"290\" OriginY=\"167.9\" UnicodeString=\"Test\"></Glyphs>";
00022 
00023         std::string lStr(lPageContent,lPageContentLength);
00024         delete [] lPageContent;
00025 
00026         // assume (postion:1243, length:459) marked, then the following code replaces the xml with new xml
00027         lStr.replace(1243, 459, lNewXML.c_str(), lNewXML.length());
00028         
00029         // write the modified content stream back to the page
00030         lPage.replaceContentStream(lStr.c_str(), lStr.length());
00031         
00032         // write the modified package out
00033         lPackage->writePackageToFile("CoreProperty2-replaced.xps");
00034 
00035         NOPackage::destroyPackage(lPackage);
00036 }

Generated on Thu Jul 19 09:33:08 2007 for NiXPS Library by  doxygen 1.5.2