|
This code snippet is taken from Form1.cs line 294 in the
AccessiblePDF example project.
This code snippet is taken from Form1.cs line 335 in the
AccessiblePDF example project.
theDoc.Read(src);
AccessibilityOperation op = new AccessibilityOperation(theDoc);
op.PageContents.AddPages();
op.MakeAccessible();
theDoc.Save(dst);
Structure tags = new Structure();
tags.Load(theDoc);
// reorder elements so that they go from top to bottom
StructureElementElement document = (StructureElementElement)tags.Root.EntryK[0];
KidArranger.SortTopToBottom(tags, document);
// determine what styles are used for headers and change tag type appropriately
List<StructureElementElement> elements = tags.FindElementsByType("P");
Dictionary<string, List<StructureElementElement>> styles = new Dictionary<string, List<StructureElementElement>>();
foreach (StructureElementElement element in elements) {
string weight = null;
if (!element.GetStyle().TryGetValue("font-weight", out weight))
continue; // we are only interested in bold fonts
int value = 0;
if ((!int.TryParse(weight, out value)) || (value < 700))
continue;
string size = null;
if (!element.GetStyle().TryGetValue("font-size", out size))
continue;
List<StructureElementElement> matches = null;
if (!styles.TryGetValue(size, out matches)) {
matches = new List<StructureElementElement>();
styles[size] = matches;
}
matches.Add(element);
}
List<Style> headers = new List<Style>();
foreach (KeyValuePair<string, List<StructureElementElement>> pair in styles)
headers.Add(new Style(pair.Key, pair.Value));
headers.Sort((i1, i2) => i1.Elements.Count.CompareTo(i2.Elements.Count));
for (int i = 0; i < headers.Count; i++) {
if (i > 4)
break; // limit the number of header levels
string tag = "H" + (i + 1).ToString();
foreach (StructureElementElement element in headers[i].Elements) {
element.EntryS = tag;
}
}
theDoc.Save(dst);
This code snippet is taken from Form1.cs line 406 in the
AccessiblePDF example project.
This code snippet is taken from Form1.cs line 435 in the
AccessiblePDF example project.
theDoc.Read(src);
AccessibilityOperation op = new AccessibilityOperation(theDoc);
op.PageContents.AddPages();
op.MakeAccessible();
theDoc.Save(dst);
Structure tags = new Structure();
tags.Load(theDoc);
// reorder elements so that they go from top to bottom
StructureElementElement document = (StructureElementElement)tags.Root.EntryK[0];
KidArranger.SortTopToBottom(tags, document);
// define structure hierarchy template
List<Heading> template = new List<Heading>();
template.Add(new Heading("Title ", "Part", 1));
template.Add(new Heading("Subheader ", "Sect", 2));
// detect and insert section item structure
List<StructureElementElement> elements = tags.FindElementsByType("P");
Stack<StructureElementElement> hierarchy = new Stack<StructureElementElement>();
foreach (StructureElementElement element in elements) {
string text = element.EntryActualText.TrimStart();
foreach (Heading item in template) {
if (text.StartsWith(item.Match)) {
while (hierarchy.Count >= item.Level)
hierarchy.Pop();
if (hierarchy.Count == item.Level - 1) {
StructureElementElement heading = new StructureElementElement(document);
heading.EntryType = "StructElem";
heading.EntryS = item.Type;
StructureElementElement parent = (StructureElementElement)element.EntryP;
int index = parent.EntryK.IndexOf(element);
heading.SetParent(hierarchy.Count > 0 ? hierarchy.Peek() : parent, index);
hierarchy.Push(heading);
}
break;
}
}
if (hierarchy.Count > 0)
element.SetParent(hierarchy.Peek(), Int32.MaxValue);
}
theDoc.Save(dst);
This code snippet is taken from TableDetection.cs line 171 in
the AccessiblePDF example project.
This code snippet is taken from TaggedPDF.cs line 61 in the
AccessiblePDF example project.
_root = new StructureElementElement(root, _catalog);
DictAtom tree = _catalog.Resolve(Atom.GetItem(_root.Atom, "ParentTree")) as DictAtom;
_parentTree = new ParentTree(this, tree);
This code snippet is taken from TaggedPDF.cs line 69 in the
AccessiblePDF example project.
|
|
|