Last active
July 1, 2016 21:54
-
-
Save ivanatpr/c153cdd2a57f459afab2d96dcd8d7dc9 to your computer and use it in GitHub Desktop.
Slight alteration of original code (not mine) from here: http://www.anotherchris.net/csharp/parsing-xfdf-pdf-annotations/
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
//Note: quickly hacked together and only tested on one file | |
string xml = File.ReadAllText(@"sample.xfdf", Encoding.UTF8); | |
XDocument doc = XDocument.Load(new StringReader(xml)); | |
var elements = doc.Root.Element(XName.Get("annots", "http://ns.adobe.com/xfdf/")) | |
.Elements(XName.Get("highlight", "http://ns.adobe.com/xfdf/")) | |
.OrderBy(e => int.Parse(e.Attribute("page").Value)); | |
StringBuilder builder = new StringBuilder(); | |
foreach (XElement element in elements) | |
{ var highlightText = element.Descendants(XName.Get("span", "http://www.w3.org/1999/xhtml")).FirstOrDefault()?.Value; | |
if (!string.IsNullOrWhiteSpace(highlightText)) | |
{ | |
var txt = String.Format("Page {0}: {1}", element.Attribute("page").Value, highlightText); | |
builder.AppendLine(txt); | |
} | |
} | |
Console.WriteLine(builder.ToString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment