|
This code snippet is taken from Form1.cs line 294 in the
AccessiblePDF example project.
If table.Items.Count <= 1 Then
continue ' too small
End If
Dim index As Integer = 0
Dim parent As StructureElementElement = Nothing
Dim tb As New StructureElementElement(document)
tb.EntryType = "StructElem"
tb.EntryS = "Table"
For Each row As Row In table.Items
Dim tr As New StructureElementElement(document)
tr.EntryType = "StructElem"
tr.EntryS = "TR"
tr.SetParent(tb)
For Each item As StructureElementElement In row.Items
If (parent Is Nothing) AndAlso (item IsNot Nothing) Then
Debug.Assert(TypeOf item.EntryP Is StructureTreeRootElement = False)
parent = TryCast(item.EntryP, StructureElementElement)
index = parent.EntryK.IndexOf(item)
End If
Dim td As New StructureElementElement(document)
td.EntryType = "StructElem"
td.EntryS = "TD"
td.SetParent(tr)
If item IsNot Nothing Then
item.SetParent(td)
End If
Next item
Next row
tb.SetParent(parent, index)
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);
theDoc.Read(src)
Dim op As New AccessibilityOperation(theDoc)
op.PageContents.AddPages()
op.MakeAccessible()
theDoc.Save(dst)
Dim tags As [Structure] = New [Structure]()
tags.Load(theDoc)
' reorder elements so that they go from top to bottom
Dim document As StructureElementElement = CType(tags.Root.EntryK(0), StructureElementElement)
KidArranger.SortTopToBottom(tags, document)
' determine what styles are used for headers and change tag type appropriately
Dim elements As List(Of StructureElementElement) = tags.FindElementsByType("P")
Dim styles As New Dictionary(Of String, List(Of StructureElementElement))()
For Each element As StructureElementElement In elements
Dim weight As String = Nothing
If Not element.GetStyle().TryGetValue("font-weight", weight) Then
Continue For ' we are only interested in bold fonts
End If
Dim value As Integer = 0
If (Not Integer.TryParse(weight, value)) OrElse (value < 700) Then
Continue For
End If
Dim size As String = Nothing
If Not element.GetStyle().TryGetValue("font-size", size) Then
Continue For
End If
Dim matches As List(Of StructureElementElement) = Nothing
If Not styles.TryGetValue(size, matches) Then
matches = New List(Of StructureElementElement)()
styles(size) = matches
End If
matches.Add(element)
Next element
Dim headers As New List(Of Style)()
For Each pair As KeyValuePair(Of String, List(Of StructureElementElement)) In styles
headers.Add(New Style(pair.Key, pair.Value))
Next pair
headers.Sort(Function(i1, i2) i1.Elements.Count.CompareTo(i2.Elements.Count))
For i As Integer = 0 To headers.Count - 1
If i > 4 Then
Exit For ' limit the number of header levels
End If
Dim tag As String = "H" & (i + 1).ToString()
For Each element As StructureElementElement In headers(i).Elements
element.EntryS = tag
Next element
Next i
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);
theDoc.Read(src)
Dim op As New AccessibilityOperation(theDoc)
op.PageContents.AddPages()
op.MakeAccessible()
theDoc.Save(dst)
Dim tags As [Structure] = New [Structure]()
tags.Load(theDoc)
' reorder elements so that they go from top to bottom
Dim document As StructureElementElement = CType(tags.Root.EntryK(0), StructureElementElement)
KidArranger.SortTopToBottom(tags, document)
' define structure hierarchy template
Dim template As New List(Of Heading)()
template.Add(New Heading("Title ", "Part", 1))
template.Add(New Heading("Subheader ", "Sect", 2))
' detect and insert section item structure
Dim elements As List(Of StructureElementElement) = tags.FindElementsByType("P")
Dim hierarchy As New Stack(Of StructureElementElement)()
For Each element As StructureElementElement In elements
Dim text As String = element.EntryActualText.TrimStart()
For Each item As Heading In template
If text.StartsWith(item.Match) Then
Do While hierarchy.Count >= item.Level
hierarchy.Pop()
Loop
If hierarchy.Count = item.Level - 1 Then
Dim heading As New StructureElementElement(document)
heading.EntryType = "StructElem"
heading.EntryS = item.Type
Dim parent As StructureElementElement = CType(element.EntryP, StructureElementElement)
Dim index As Integer = parent.EntryK.IndexOf(element)
heading.SetParent(If(hierarchy.Count > 0, hierarchy.Peek(), parent), index)
hierarchy.Push(heading)
End If
Exit For
End If
Next item
If hierarchy.Count > 0 Then
element.SetParent(hierarchy.Peek(), Int32.MaxValue)
End If
Next element
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);
_root = New StructureElementElement(root, _catalog)
Dim tree As DictAtom = TryCast(_catalog.Resolve(Atom.GetItem(_root.Atom, "ParentTree")), DictAtom)
_parentTree = New ParentTree(Me, tree)
This code snippet is taken from TaggedPDF.cs line 69 in the
AccessiblePDF example project.
|
|
|