Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Last active January 18, 2021 20:08
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/b2d6e3d3e4afab81c71335ff5054b363 to your computer and use it in GitHub Desktop.
Save bjoerntx/b2d6e3d3e4afab81c71335ff5054b363 to your computer and use it in GitHub Desktop.
private string GetXmlAttachment(string Filename) {
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
tx.Create();
// load documment
LoadSettings ls = new TXTextControl.LoadSettings() {
PDFImportSettings = PDFImportSettings.LoadEmbeddedFiles
};
tx.Load(Filename, TXTextControl.StreamType.AdobePDF, ls);
// all attachments
var embeddedFiles = ls.EmbeddedFiles;
// find the "alternative" xml representation
foreach (EmbeddedFile embeddedFile in embeddedFiles) {
if (embeddedFile.Relationship == "Alternative" &&
embeddedFile.MIMEType == "text/xml") {
// return converted XML
return Encoding.UTF8.GetString((byte[])embeddedFile.Data);
}
}
return null; //something went wrong
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment