IXpsOMObjectFactory::CreatePackageFromFile method (xpsobjectmodel.h)

Opens an XPS package file and returns an instantiated XPS document object tree.

Syntax

HRESULT CreatePackageFromFile(
  [in]          LPCWSTR       filename,
  [in]          BOOL          reuseObjects,
  [out, retval] IXpsOMPackage **package
);

Parameters

[in] filename

The name of the XPS package file.

[in] reuseObjects

A Boolean value that indicates whether the software is to attempt to optimize the document object tree by sharing objects that are identical in all properties and children.

Value Meaning
TRUE
The software will attempt to optimize the object tree.
FALSE
The software will not attempt to optimize the object tree.

[out, retval] package

A pointer to the new IXpsOMPackage interface that contains the resulting XPS document object tree.

Return value

The method returns an HRESULT. Possible values include, but are not limited to, those in the table that follows. For information about XPS document API return values that are not listed in this table, see XPS Document Errors.

Return code Description
S_OK
The method succeeded.
E_POINTER
filename or package is NULL.
 

This method calls the Packaging API. For information about the Packaging API return values, see Packaging Errors.

Remarks

This method does not validate the contents of any stream-based resources that it loads from the stream into the objects of the XPS OM. Instead, the application must validate these resources before it uses them.

This method does not deserialize the document pages; it only deserializes the XPS package down to the page reference parts. The actual pages can be deserialized as they are needed, by calling the IXpsOMPageReference::GetPage method. Because the pages are not deserialized when GetPage is called, it is possible for this method to return S_OK or, if an attempt is made to load a problematic page in an XPS package, to return an error.

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 a case are listed in the table that follows:

Document feature Action
Digital signatures Removed from document
DiscardControl part Removed from document
Foreign document parts Removed from document
FixedPage markup Modified from original
Resource dictionary markup Modified from original if Optimization flag is set
 

For information about using IXpsOMPackage interface in a program, see Create a Blank XPS OM.

Requirements

Requirement Value
Minimum supported client Windows 7, Windows Vista with SP2 and Platform Update for Windows Vista [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header xpsobjectmodel.h

See also

Create a Blank XPS OM

IXpsOMObjectFactory

IXpsOMPackage

IXpsOMPageReference::GetPage

Packaging Errors

XML Paper Specification

XPS Document Errors