Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created June 24, 2021 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/c03e67da1f909bfd70f2544ebcef7850 to your computer and use it in GitHub Desktop.
Save bjoerntx/c03e67da1f909bfd70f2544ebcef7850 to your computer and use it in GitHub Desktop.
public static void SaveAnnotations(SmartDocument smartDocument) {
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
tx.Create();
// load the SmartDocument PDF
TXTextControl.LoadSettings loadSettings = new LoadSettings();
tx.Load("App_Data/" + smartDocument.Name,
TXTextControl.StreamType.AdobePDF,
loadSettings);
// find the original embedded document
foreach (EmbeddedFile file in loadSettings.EmbeddedFiles) {
if (file.FileName == "original.tx")
smartDocument.Document = Convert.ToBase64String((byte[])file.Data);
}
// load the original document
tx.Load(Convert.FromBase64String(smartDocument.Document),
BinaryStreamType.InternalUnicodeFormat);
// create an attachment for the original document
EmbeddedFile efOriginal = new EmbeddedFile("original.tx",
Convert.FromBase64String(smartDocument.Document),
null);
efOriginal.Relationship = "Source";
// create an attachment for the annotations
EmbeddedFile efAnnotations = new EmbeddedFile("annotations.json",
Encoding.UTF8.GetBytes(smartDocument.Annotations),
null);
efAnnotations.Relationship = "Source";
// attach the files
TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings() {
EmbeddedFiles = new EmbeddedFile[] { efOriginal, efAnnotations }
};
// save the SmartDocument as PDF with attachments
tx.Save("App_Data/" + smartDocument.Name,
TXTextControl.StreamType.AdobePDF,
saveSettings);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment