PDF/A-3 allows files of any format to be embedded. PDF/A-3 documents enable the transition from electronic paper to an electronic container that contains both human- and machine-readable versions of a document. Applications can extract the machine-readable portion of the PDF document for processing. A PDF/A-3 document can contain an unlimited number of embedded documents for different processes.

Smart Document Container

This standard can also be used to store different versions of a document in the same container. This container is a PDF/A-3 document, where the cover document is always the latest version of the document. This human-readable version can be viewed in any PDF reader, and editable versions are attached to the document. When a new version is created, the editable version is attached and the cover document is replaced.

The following illustration shows the layers of a PDF/A-3 document with the PDF cover document (human readable) and additional attached editable documents. This illustration shows an additional annotation layer representing JSON data added by the TX Text Control Document Viewer.

PDF/A-3 Document

The advantage of this scenario is that the PDF can be sent to anyone outside your infrastructure, and the current version of the document is always visible to anyone with a simple Acrobat Reader. The viewable version is always the most current version.

Create the Container

The following code shows how to use the ServerTextControl TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
ServerTextControl Class
The ServerTextControl class implements a component that provide high-level text processing features for server-based applications.
class to create a new PDF document with an attached document in the internal TX Text Control format for editing. The EmbeddedFiles TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
LoadSaveSettingsBase Class
EmbeddedFiles Property
Specifies an array of EmbeddedFile objects which will be embedded in the saved document.
property is used to attach documents to the array of attached documents.

public string CreateNewDocument(byte[] document) {
var DocumentName = Guid.NewGuid().ToString() + ".pdf";
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
tx.Create();
tx.Load(document, BinaryStreamType.InternalUnicodeFormat);
byte[] dataTx;
// save the blank document in the internal TX format
tx.Save(out dataTx, TXTextControl.BinaryStreamType.InternalUnicodeFormat);
// create an attachment
EmbeddedFile embeddedFile = new EmbeddedFile("original.tx", dataTx, null);
embeddedFile.Relationship = "Source";
TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings() {
EmbeddedFiles = new EmbeddedFile[] { embeddedFile }
};
// save a PDF with the attached Text Control document embedded
tx.Save(DocumentName,
TXTextControl.StreamType.AdobePDF,
saveSettings);
}
return DocumentName;
}
view raw test.cs hosted with ❤ by GitHub

Extract the Editable Document

The ExtractSmartDocument method loads a PDF/A-3 document and extracts the most recent original TX Text Control document from the attached files, which is returned as a byte array.

public byte[] ExtractSmartDocument(string DocumentName) {
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
tx.Create();
// the load PDF document
TXTextControl.LoadSettings loadSettings = new LoadSettings();
tx.Load(DocumentName,
TXTextControl.StreamType.AdobePDF,
loadSettings);
// loop through all attachments to find the original document
// and the annotations
foreach (EmbeddedFile file in loadSettings.EmbeddedFiles.Reverse()) {
if (file.FileName == "original.tx")
return (byte[])file.Data;
}
}
return null;
}
view raw test.cs hosted with ❤ by GitHub

Update the Container

The UpdateDocument method loads the smart PDF document to add a new original document to the list of attachments. A timestamp is automatically stored, so the above method ExtractSmartDocument only needs to check for the last added document.

public string UpdateDocument(string DocumentName, byte[] document) {
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
tx.Create();
// the load PDF document
TXTextControl.LoadSettings loadSettings = new LoadSettings();
tx.Load(DocumentName,
TXTextControl.StreamType.AdobePDF,
loadSettings);
List<EmbeddedFile> embeddedFiles = loadSettings.EmbeddedFiles.ToList();
// create an attachment
EmbeddedFile embeddedFile = new EmbeddedFile("original.tx", document, null);
embeddedFile.Relationship = "Source";
embeddedFiles.Add(embeddedFile);
TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings() {
EmbeddedFiles = embeddedFiles.ToArray()
};
tx.Load(document, BinaryStreamType.InternalUnicodeFormat);
// save a PDF with the attached Text Control document embedded
tx.Save(DocumentName,
TXTextControl.StreamType.AdobePDF,
saveSettings);
}
return DocumentName;
}
view raw test.cs hosted with ❤ by GitHub