使用 IXpsOMPageReference 接口
本主题介绍 XPS OM 中提供页面引用访问的接口的使用方法。
接口名称 | 逻辑子接口 | 说明 |
---|---|---|
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 );
相关主题
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈