Working with IXpsOMPageReference Interfaces
This topic describes how to use the interfaces that provide access to page references in an XPS OM.
Interface name | Logical child interfaces | Description |
---|---|---|
Virtualizes the content of a document page. A page reference contains basic information about the page, some page properties, and a link to the page contents. The IXpsOMPage interface that comprises page contents is returned by the IXpsOMPageReference::GetPage method. |
||
None |
Contains a list of page items that are hyperlink targets. The list is returned by the IXpsOMPageReference::CollectLinkTargets method. |
|
None |
Contains a list of the part-based resources that are associated with the page. This list is returned by the IXpsOMPageReference::CollectPartResources method. |
Code Examples
The following code examples illustrate how to work with the page reference interfaces in a program.
- Get the page contents
- Get the list of hyperlink targets on this page
- Get the part resources that are associated with this page
Get the page contents
The following code example gets a pointer to the IXpsOMPage interface that comprises the page contents. If the page has not been loaded into the XPS OM, as happens when the XPS OM is initialized by calling IXpsOMObjectFactory::CreatePackageFromFile, calling IXpsOMPageReference::GetPage will load the page into the XPS OM.
{
HRESULT hr = S_OK;
IXpsOMPage *page = NULL;
// pageRef contains the current page reference
// and is passed in as a parameter
// get the page content of this page reference
hr = pageRef->GetPage (&page);
Get the list of hyperlink targets on this page
The following code example gets a pointer to the IXpsOMNameCollection interface that contains the list of page items that are hyperlink targets. If the page has not been loaded into the XPS OM, the list of hyperlink targets is read from the PageContent.LinkTargets markup. If the page has been loaded, CollectLinkTargets checks each element in the page and returns a list of elements whose IsHyperlinkTarget attribute is TRUE.
HRESULT hr = S_OK;
IXpsOMPage *page = NULL;
IXpsOMNameCollection *linkTargets = NULL;
UINT32 numTargets = 0;
UINT32 thisTarget = 0;
LPWSTR thisTargetName = NULL;
// pageRef contains the current page reference
// if the page hasn't been loaded yet, for example, if the XPS OM
// was loaded from an XPS document, CollectLinkTargets obtains the
// list of link targets from the <PageContent.LinkTargets> markup
hr = pageRef->CollectLinkTargets(&linkTargets);
// get the page content of this page reference
hr = pageRef->GetPage (&page);
// after the page object has been loaded and calling GetPage or
// by creating a page in the XPS OM, CollectLinkTargets will now check
// each of the page elements to return the list so this call to
// CollectLinkTargets might take longer to return than the previous
// call above if the XPS OM was created from a file
linkTargets->Release(); // release previous collection
hr = pageRef->CollectLinkTargets(&linkTargets);
// walk the list of link targets returned
hr = linkTargets->GetCount( &numTargets );
thisTarget = 0;
while (thisTarget < numTargets) {
hr = linkTargets->GetAt (thisTarget, &thisTargetName);
printf ("%s\n", thisTargetName);
// release the target string returned to prevent memory leaks
CoTaskMemFree (thisTargetName);
// get next target in list
thisTarget++;
}
// release page and the link target collection
page->Release();
linkTargets->Release();
Get the part resources that are associated with this page
The following code example gets the lists of the different resources that are used by this page.
HRESULT hr = S_OK;
IXpsOMPartResources *resources;
IXpsOMColorProfileResourceCollection *colorProfileResources;
IXpsOMFontResourceCollection *fontResources;
IXpsOMImageResourceCollection *imageResources;
IXpsOMRemoteDictionaryResourceCollection *dictionaryResources;
// pageRef contains the current page reference
hr = pageRef->CollectPartResources ( &resources );
// Get pointers to each type of resource
hr = resources->GetColorProfileResources( &colorProfileResources );
hr = resources->GetFontResources( &fontResources );
hr = resources->GetImageResources( &imageResources );
hr = resources->GetRemoteDictionaryResources( &dictionaryResources );