Partager via


Read an XPS Document into an XPS OM

Describes how to read an existing XPS document from a file into an XPS OM.

To create an XPS OM from an XPS document, call the IXpsOMObjectFactory::CreatePackageFromFile method.

Before using these code examples in your program, read the disclaimer in Common XPS Document Programming Tasks.

Code Example

The following code example assumes that the initialization described in Initialize an XPS OM has succeeded.

    IXpsOMPackage *package = NULL;

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

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

    // When finished with the package, release the object.
    if (NULL != package) package->Release();

To create an XPS OM from an XPS document that is stored as a stream, call IXpsOMObjectFactory::CreatePackageFromStream.

Remarks

If you write an XPS OM immediately after you have read an XPS package into it, some of the original content might be lost or changed.

Some of the changes that can occur in such case are listed in the table that follows:

Document feature Action

Digital signatures

Removed from the document

DiscardControl part

Removed from the document

Foreign document parts

Removed from the document

FixedPage markup

Modified from the original

Resource dictionary markup

Modified from the original, if Optimization flag is set

 

Next Steps

Navigate the XPS OM

Write Text to an XPS OM

Draw Graphics in an XPS OM

Place Images in an XPS OM

Used in This Section

IXpsOMObjectFactory

IXpsOMPackage

For More Information

Initialize an XPS OM

Packaging API

XPS Document API Reference

XML Paper Specification