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 文档。
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();