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

XPS OM Package Interfaces

· 52CE 我爱测

The package interfaces represent the top level of the XPS OM, which corresponds to an XPS document file.

The package interfaces represent the top level of the XPS OM, which corresponds to an XPS document file. These interfaces contain methods that serialize an XPS OM to an XPS document or stream, and deserialize an XPS package to create an XPS OM that enables a program to access the contents of a document.

Interface name Logical child interfaces Description
IXpsOMPackage IXpsOMDocumentSequence IXpsOMCoreProperties The complete XPS OM that corresponds to the package that contains the XPS document.
IXpsOMPackageWriter None Enables incremental serialization of document pages to a package.
IXpsOMCoreProperties None Accesses the document metadata.

Code Examples

The code examples that follow illustrate how some of the package interfaces are used by a program. Unless noted otherwise, all italicized items are parameter names.

Read an XPS document into an XPS OM

From an existing XPS document whose file name is stored in xpsDocumentFilename, this code example creates an XPS OM that is referenced by xpsPackage.

    HRESULT                 hr = S_OK;
    IXpsOMPackage           *xpsPackage;

    hr = xpsFactory->CreatePackageFromFile(
        xpsDocumentFilename,
        FALSE,
        &xpsPackage);

    // xpsPackage now contains a pointer to the IXpsOMPackage
    // object that has been populated with the contents
    // of the XPS document in xpsDocumentFilename.

Write an XPS OM to an XPS document file

The following code example writes the XPS OM that is referenced by xpsPackage. The example creates an XPS document in the file whose name is stored in fileName.

    HRESULT hr = S_OK;

    hr = xpsPackage->WriteToFile(
        xpsDocumentFilename,
        NULL,                    // LPSECURITY_ATTRIBUTES
        FILE_ATTRIBUTE_NORMAL,
        FALSE);                  // optimizeMarkupSize

Access the document sequence of the XPS OM

The following code example obtains a pointer to the IXpsOMDocumentSequence interface, which contains the document sequence of the XPS OM that is represented by xpsPackage.

    HRESULT                         hr = S_OK;
    IXpsOMDocumentSequence          *docSeq;
    IXpsOMDocumentCollection        *docs;

    // get the fixed document sequence of the package
    hr = xpsPackage->GetDocumentSequence(&docSeq);

    // get the collection of fixed documents in 
    //  the fixed document sequence
    hr = docSeq->GetDocuments(&docs);

Access the document's CoreProperties

The following is code example obtains a pointer to the IXpsOMCoreProperties interface, allowing the program to access the contents of the CoreProperties part. In the example, the document is assumed to have been read into an XPS OM that is represented by xpsPackage.

    HRESULT                         hr = S_OK;
    IXpsOMCoreProperties            *coreProps;
    LPWSTR                          title;

    // get the fixed document sequence of the package
    hr = xpsPackage->GetCoreProperties(&coreProps);

    // get the title property 
    hr = coreProps->GetTitle(&title);

    // do something with the title property here...

    // free the string when finished with it
    CoTaskMemFree ( title );
    coreProps->Release();

Related topics

Using the IXpsOMPackageWriter Interface

Navigate the XPS OM

IXpsOMDocumentSequence Interface

IXpsOMPackage Interface

IXpsOMPackageWriter Interface

IXpsOMCoreProperties Interface

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)

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

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