I am trying to add comments in XPS document. Is it possible with .Net API and read them back? I need to add hidden text embedded in XPS file.
You can add metadata to an XPS document file by using the XpsDocument
class and its CoreDocumentProperties
property.
I'm not sure if this would satisfy your requirements, but here's how to do it.
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
}
}
}
You can access this information via code by creating a new XpsDocument
with read access, ie.
using (var document = new XpsDocument(XpsFilePath, FileAccess.Read))
{
PackageProperties properties = document.CoreDocumentProperties;
System.Console.WriteLine(properties.Title);
// etc...
}
You can view the metadata for the XPS document in Windows by right-clicking on the file, choosing Properties, then showing the Details tab:
The metadata isn't strictly hidden, as you can see it in Windows using the above technique or access it via code. However, it isn't displayed on the actual pages of the XPS document, so is not normally visible when viewing or printing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With