大网数据广告活动
打印与设备

Working with IXpsOMPageReference Interfaces

· 52CE 我爱测

This topic describes how to use the interfaces that provide access to page references in an XPS OM.

This topic describes how to use the interfaces that provide access to page references in an XPS OM.

Interface name Logical child interfaces Description
IXpsOMPageReference IXpsOMPage 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.
IXpsOMNameCollection None Contains a list of page items that are hyperlink targets. The list is returned by the IXpsOMPageReference::CollectLinkTargets method.
IXpsOMPartResources 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

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 );

Related topics

IXpsOMNameCollection

IXpsOMPage

IXpsOMPageReference

IXpsOMPartResources

XML Paper Specification

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。