Created
June 24, 2021 14:13
-
-
Save bjoerntx/c03e67da1f909bfd70f2544ebcef7850 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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