本主题介绍如何使用提供对 XPS OM 中的页面引用的访问权限的接口。
| 接口名称 | 逻辑子接口 | DESCRIPTION |
|---|---|---|
| IXpsOMPageReference |
IXpsOMPage |
虚拟化文档页面的内容。 页面引用包含有关页面的基本信息、一些页面属性和指向页面内容的链接。 由 IXpsOMPageReference::GetPage 方法返回包含页面内容的 IXpsOMPage 接口。 |
| IXpsOMNameCollection |
没有 |
包含作为超链接目标的页面项的列表。 列表由 IXpsOMPageReference::CollectLinkTargets 方法返回。 |
| IXpsOMPartResources |
没有 |
包含与页面关联的基于部件的资源的列表。 此列表由 IXpsOMPageReference::CollectPartResources 方法返回。 |
代码示例
以下代码示例演示如何在程序中使用页面引用接口。
获取页面内容
下面的代码示例获取指向包含页面内容的 IXpsOMPage 接口的指针。 如果尚未将页面加载到 XPS OM 中,则调用 IXpsOMObjectFactory::CreatePackageFromFile 初始化 XPS OM 时,调用 IXpsOMPageReference::GetPage 会将页面加载到 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);
获取此页上的超链接目标列表
下面的代码示例获取指向 IXpsOMNameCollection 接口的指针,该接口包含超链接目标的页面项列表。 如果页面尚未加载到 XPS OM 中,将从 PageContent.LinkTargets 标记读取超链接目标列表。 如果页面已加载, CollectLinkTargets 将检查页面中的每个元素,并返回 IsHyperlinkTarget 属性为 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();
获取与此页关联的部件资源
下面的代码示例获取此页面使用的不同资源的列表。
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 );