Smart Documents: Embed Document Versions in PDF/A-3 Containers
TX Text Control can embed and extract embedded files into and from PDF documents. This can be used to create intelligent document containers consisting of the original document for editing.

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.
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 Server
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;
}
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;
}
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;
}
ASP.NET
Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.
- Angular
- Blazor
- React
- JavaScript
- ASP.NET MVC, ASP.NET Core, and WebForms
Related Posts
Mining PDFs with Regex in C#: Practical Patterns, Tips, and Ideas
Mining PDFs with Regex in C# can be a powerful technique for extracting information from documents. This article explores practical patterns, tips, and ideas for effectively using regular…
PDF Conversion in .NET: Convert DOCX, HTML and more with C#
PDF conversion in .NET is a standard requirement for generating invoices, templates, and accessible reports. This article provides an overview of PDF conversion capabilities using TX Text Control,…
Streamline Data Collection with Embedded Forms in C# .NET
Discover how to enhance your C# .NET applications by embedding forms for data collection. This article explores the benefits of using Text Control's ASP.NET and ASP.NET Core components to create…
Adding QR Codes to PDF Documents in C# .NET
This article explains how to add QR codes to PDF documents with the Text Control .NET Server component in C#. It provides the necessary steps and code snippets for effectively implementing this…
Adding SVG Graphics to PDF Documents in C# .NET
In this article, we will explore how to add SVG graphics to PDF documents using C# .NET. We will use the TX Text Control .NET Server component to demonstrate the process of rendering SVG images in…