XPS OM 包接口
包接口表示 XPS OM 的顶级,它对应于 XPS 文档文件。 这些接口包含的方法将 XPS OM 序列化为 XPS 文档或流,并反序列化 XPS 包以创建 XPS OM,使程序能够访问文档的内容。
接口名称 | 逻辑子接口 | 说明 |
---|---|---|
IXpsOMPackage |
IXpsOMDocumentSequence IXpsOMCoreProperties |
对应于包含 XPS 文档的包的完整 XPS OM。 |
IXpsOMPackageWriter |
无 |
启用文档页到包的增量序列化。 |
IXpsOMCoreProperties |
无 |
访问文档元数据。 |
代码示例
下面的代码示例演示了程序如何使用某些包接口。 除非另有说明,否则所有斜体项都是参数名称。
将 XPS 文档读取到 XPS OM 中
从文件名存储在 xpsDocumentFilename 中的现有 XPS 文档中,此代码示例创建由 xpsPackage 引用的 XPS OM。
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.
将 XPS OM 写入 XPS 文档文件
下面的代码示例编写由 xpsPackage 引用的 XPS OM。 该示例在文件中创建一个 XPS 文档,其名称存储在 fileName 中。
HRESULT hr = S_OK;
hr = xpsPackage->WriteToFile(
xpsDocumentFilename,
NULL, // LPSECURITY_ATTRIBUTES
FILE_ATTRIBUTE_NORMAL,
FALSE); // optimizeMarkupSize
访问 XPS OM 的文档序列
下面的代码示例获取指向 IXpsOMDocumentSequence 接口的指针,该接口包含由 xpsPackage 表示的 XPS OM 的文档序列。
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);
访问文档的 CoreProperties
下面的代码示例获取指向 IXpsOMCoreProperties 接口的指针,允许程序访问 CoreProperties 部件的内容。 在此示例中,假定文档已读入 xpsPackage 表示的 XPS OM 中。
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();