Reading and writing of hidden text using PDFNet SDK

Q:
How can I implement the following requirements using PDFNet SDK?

1. Users will embed a text document into the PDF which shall not
ordinarily be visible/printable.
2. Our application then needs to extract the embedded document and read
the non-printable
characters .
----
A:
Using PDFNet SDK (http://www.pdftron.com/net) there are several ways
you could implement this functionality. For example,

a) if you want to make invisible text that is part of the standard
content stream you could set GState.TextRenderingMode.e_invisible_text
in the graphics state when creating new text. See 'How do I create 'PDF
Searchable Images'? -
http://www.pdftron.com/net/faq.html#searchable_images. With this
approach the text will be hidden, however it will not prevent the end
user from selecting the text or third party applications to extract the
text.

b) You can embed the text file using standard PDF file attachment
mechanism. For example:

// In C#
FileSpec fs = FileSpec.Create(pdfdoc, "mydata.txt", true);
pdfdoc.AddFileAttachment("MyFile", fs);

With this approach the text will be invisible, however the end user
will still be able to extract the data through document attachments
panel in Acrobat.

c) To make the text completely invisible to the end user and third
party applications you can also use PDFNet's Cos/SDF API to associate
text content with any object in PDF. For example, the following code
associates a text stream with a given PDF page object:

// Embed a custom text stream using PDFNet's SDF/Cos API.
StdFile embed_file = new StdFile("my_stream.txt",
StdFile.OpenMode.e_read_mode);
FilterReader mystm = new FilterReader(embed_file);
page.GetSDFObj().Put("MySecretKey",
pdfdoc.CreateIndirectStream(mystm));

On the input side you would access your custom data stream as follows:

Page page = ...;
Obj my_stream = page.GetSDFObj().FindObj("MySecretKey");
if (my_stream != null) {
  FilterReader reader = new FilterReader(my_stream.GetDecodedStream());
  reader.Read(...);
  ... process the custom data ...
}

You can also encrypt the data stream it the custom data is considered
confidential.