gpt4 book ai didi

wpf - XPS 文档中的注释

转载 作者:行者123 更新时间:2023-12-04 18:56:37 26 4
gpt4 key购买 nike

我正在尝试在 XPS 文档中添加注释。是否可以使用 .Net API 并读取它们?我需要添加嵌入在 XPS 文件中的隐藏文本。

最佳答案

您可以使用 XpsDocument class 将元数据添加到 XPS 文档文件中。和它的 CoreDocumentProperties property .

我不确定这是否能满足您的要求,但这是如何做到的。

using System.IO;
using System.IO.Packaging;
using System.Windows.Xps.Packaging;

namespace StackOverflow
{
class Program
{
static void Main(string[] args)
{
const string XpsFilePath = @" ... path to XPS file ... ";

using (var document = new XpsDocument(XpsFilePath, FileAccess.ReadWrite))
{
PackageProperties properties = document.CoreDocumentProperties;
properties.Title = "Some title";
properties.Subject = "Some subject line";
properties.Keywords = "stackoverflow xps";
properties.Category = "Some category";
properties.Description = "Some kind of document";
properties.Creator = "me";
properties.LastModifiedBy = "me again";
properties.Revision = "Rev A";
properties.Version = "v1";
}

// XpsDocument is from System.Windows.Xps.Packaging, in ReachFramework assembly
// PackageProperties is from System.IO.Packaging, in WindowsBase assembly
}
}
}

您可以通过创建新的 XpsDocument 来通过代码访问此信息。具有读取权限,即。
using (var document = new XpsDocument(XpsFilePath, FileAccess.Read))
{
PackageProperties properties = document.CoreDocumentProperties;
System.Console.WriteLine(properties.Title);
// etc...
}

您可以在 Windows 中通过右键单击文件,选择属性,然后显示详细信息选项卡来查看 XPS 文档的元数据:

Properties for XPS document

元数据不是严格隐藏的,因为您可以使用上述技术在 Windows 中看到它或通过代码访问它。但是,它不会显示在 XPS 文档的实际页面上,因此在查看或打印时通常不可见。

关于wpf - XPS 文档中的注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51156233/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com