public void StyleSheetTableTest() { RtfStyleSheetTable styleTable = tree.GetStyleSheetTable(); Assert.That(styleTable.Count, Is.EqualTo(7)); Assert.That(styleTable[0].Index, Is.EqualTo(0)); Assert.That(styleTable[0].Type, Is.EqualTo(RtfStyleSheetType.Paragraph)); Assert.That(styleTable[0].Name, Is.EqualTo("Normal")); Assert.That(styleTable[0].Next, Is.EqualTo(0)); Assert.That(styleTable[0].Formatting.Count, Is.EqualTo(25)); Assert.That(styleTable[1].Index, Is.EqualTo(1)); Assert.That(styleTable[1].Type, Is.EqualTo(RtfStyleSheetType.Paragraph)); Assert.That(styleTable[1].Name, Is.EqualTo("heading 1")); Assert.That(styleTable[1].Next, Is.EqualTo(0)); Assert.That(styleTable[1].BasedOn, Is.EqualTo(0)); Assert.That(styleTable[1].Styrsid, Is.EqualTo(2310575)); Assert.That(styleTable[1].Formatting.Count, Is.EqualTo(33)); Assert.That(styleTable[10].Index, Is.EqualTo(10)); Assert.That(styleTable[10].Type, Is.EqualTo(RtfStyleSheetType.Character)); Assert.That(styleTable[10].Name, Is.EqualTo("Default Paragraph Font")); Assert.That(styleTable[10].Additive, Is.EqualTo(true)); Assert.That(styleTable[10].SemiHidden, Is.EqualTo(true)); Assert.That(styleTable[10].Formatting.Count, Is.EqualTo(0)); Assert.That(styleTable[11].Index, Is.EqualTo(11)); Assert.That(styleTable[11].Type, Is.EqualTo(RtfStyleSheetType.Table)); Assert.That(styleTable[11].Name, Is.EqualTo("Normal Table")); Assert.That(styleTable[11].Next, Is.EqualTo(11)); Assert.That(styleTable[11].SemiHidden, Is.EqualTo(true)); Assert.That(styleTable[11].Formatting.Count, Is.EqualTo(44)); }
public static void ExtractDocumentOutline() { RtfTree tree = new RtfTree(); tree.LoadRtfFile("..\\..\\testdocs\\test-doc.rtf"); RtfStyleSheetTable sst = tree.GetStyleSheetTable(); int heading1 = sst.IndexOf("heading 1"); int heading2 = sst.IndexOf("heading 2"); int heading3 = sst.IndexOf("heading 3"); tree.MainGroup.RemoveChild(tree.MainGroup.SelectChildGroups("stylesheet")[0]); RtfNodeCollection headingKeywords = tree.MainGroup.SelectNodes("s"); for (int i = 0; i < headingKeywords.Count; i++) { RtfTreeNode hk = headingKeywords[i]; StringBuilder text = new StringBuilder(""); if (hk.Parameter == heading1 || hk.Parameter == heading2 || hk.Parameter == heading3) { RtfTreeNode sibling = hk.NextSibling; while (sibling != null && !sibling.NodeKey.Equals("pard")) { if (sibling.NodeType == RtfNodeType.Text) { text.Append(sibling.NodeKey); } else if (sibling.NodeType == RtfNodeType.Group) { text.Append(ExtractGroupText(sibling)); } sibling = sibling.NextSibling; } if (hk.Parameter == heading1) { Console.WriteLine("H1: {0}", text); } else if (hk.Parameter == heading2) { Console.WriteLine(" H2: {0}", text); } else if (hk.Parameter == heading3) { Console.WriteLine(" H3: {0}", text); } } } }
public static void ExtractDocumentOutline() { RtfTree tree = new RtfTree(); tree.LoadRtfFile("..\\..\\testdocs\\test-doc.rtf"); RtfStyleSheetTable sst = tree.GetStyleSheetTable(); int heading1 = sst.IndexOf("heading 1"); int heading2 = sst.IndexOf("heading 2"); int heading3 = sst.IndexOf("heading 3"); tree.MainGroup.RemoveChild(tree.MainGroup.SelectChildGroups("stylesheet")[0]); RtfNodeCollection headingKeywords = tree.MainGroup.SelectNodes("s"); for (int i = 0; i < headingKeywords.Count; i++) { RtfTreeNode hk = headingKeywords[i]; StringBuilder text = new StringBuilder(""); if (hk.Parameter == heading1 || hk.Parameter == heading2 || hk.Parameter == heading3) { RtfTreeNode sibling = hk.NextSibling; while (sibling != null && !sibling.NodeKey.Equals("pard")) { if (sibling.NodeType == RtfNodeType.Text) text.Append(sibling.NodeKey); else if (sibling.NodeType == RtfNodeType.Group) text.Append(ExtractGroupText(sibling)); sibling = sibling.NextSibling; } if (hk.Parameter == heading1) Console.WriteLine("H1: {0}", text); else if (hk.Parameter == heading2) Console.WriteLine(" H2: {0}", text); else if (hk.Parameter == heading3) Console.WriteLine(" H3: {0}", text); } } }