public string GenerateTableOfContent(TableOfContent tableOfContent)
        {
            StringBuilder textBuilder = new StringBuilder();

            textBuilder.AppendLine(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
            textBuilder.AppendLine(@"<ncx xmlns=""http://www.daisy.org/z3986/2005/ncx/"" version=""2005-1"">");
            textBuilder.AppendLine(@"<head>");
            textBuilder.AppendLine(@"<meta name=""cover"" content=""cover""/>");
            textBuilder.AppendLine(@"</head>");
            textBuilder.AppendLine(@"<docTitle>");
            textBuilder.AppendLine($@"<text>{tableOfContent.Title}</text>");
            textBuilder.AppendLine(@"</docTitle>");
            textBuilder.AppendLine(@"<navMap>");
            int index = 1;

            foreach (var node in tableOfContent.Nodes)
            {
                textBuilder.AppendLine($@"<navPoint id=""{node.Abbreviation}"" playOrder=""{index}"">");
                textBuilder.AppendLine("<navLabel>");
                textBuilder.AppendLine($"<text>{node.Title}</text>");
                textBuilder.AppendLine("</navLabel>");
                textBuilder.AppendLine($@"<content src=""{node.Src}""/>");
                textBuilder.AppendLine("</navPoint>");
                index++;
            }
            textBuilder.AppendLine("</navMap>");
            textBuilder.AppendLine("</ncx>");
            return(textBuilder.ToString());
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Document doc     = new Document();
            Section  section = doc.AddSection();
            //Customizing table of contents with switches
            TableOfContent toc  = new TableOfContent(doc, "{\\o \"1-3\" \\n 1-1}");
            Paragraph      para = section.AddParagraph();

            para.Items.Add(toc);
            para.AppendFieldMark(FieldMarkType.FieldSeparator);
            para.AppendText("TOC");
            para.AppendFieldMark(FieldMarkType.FieldEnd);
            doc.TOC = toc;
            //create paragraph and set the head level
            Paragraph para1 = section.AddParagraph();

            para1.AppendText("Head1");
            para1.ApplyStyle(BuiltinStyle.Heading1);
            Paragraph para2 = section.AddParagraph();

            para2.AppendText("Head2");
            para2.ApplyStyle(BuiltinStyle.Heading2);
            Paragraph para3 = section.AddParagraph();

            para3.AppendText("Head3");
            para3.ApplyStyle(BuiltinStyle.Heading3);
            //update
            doc.UpdateTableOfContents();
            doc.SaveToFile("result.docx", FileFormat.Docx);


            FileViewer("result.docx");
        }
示例#3
0
        // 点击 第二个Menu
        // 将绘制的要素添加到shp文件中
        private void add2SHPStart_Click(object sender, RoutedEventArgs e)
        {
            layersComboBox.Items.Clear();

            TableOfContent t          = (TableOfContent)w.FindName("myTableOfContent");
            int            tempInt    = 0;
            String         tempString = "";
            string         fileType   = "";

            for (int i = 0; i < /*ArcGISApp1.Controls.TableOfContent*/ t.myLayerList.Items.Count; i++)
            {
                CheckBox cb = (CheckBox)t.myLayerList.Items[i];

                tempInt    = int.Parse(cb.Name.Substring(16));
                tempString = (cb.Content + "");
                fileType   = tempString.Substring(tempString.Length - 3);

                if (cb.IsChecked == true && (fileType == "shp" || fileType == "SHP"))
                {
                    intList.Add(int.Parse(cb.Name.Substring(16)));
                    layersComboBox.Items.Add(cb.Content);
                }
            }

            layersComboBox.IsEnabled = true;
        }
示例#4
0
        /// <summary>
        /// Finds the last TOC item from consequence text body items.
        /// </summary>
        /// <param name="toc"></param>
        /// <param name="fieldStack"></param>
        /// <returns></returns>
        private static Entity FindLastItemInTextBody(TableOfContent toc, Stack <Entity> fieldStack)
        {
            WTextBody tBody = toc.OwnerParagraph.OwnerTextBody;

            for (int i = tBody.ChildEntities.IndexOf(toc.OwnerParagraph) + 1; i < tBody.ChildEntities.Count; i++)
            {
                WParagraph paragraph = tBody.ChildEntities[i] as WParagraph;

                foreach (Entity item in paragraph.Items)
                {
                    if (item is WField)
                    {
                        fieldStack.Push(item);
                    }
                    else if (item is WFieldMark && (item as WFieldMark).Type == FieldMarkType.FieldEnd)
                    {
                        if (fieldStack.Count == 1)
                        {
                            fieldStack.Clear();
                            return(item);
                        }
                        else
                        {
                            fieldStack.Pop();
                        }
                    }
                }
            }
            return(null);
        }
 static void Main(string[] args)
 {
     using (WordDocument document = new WordDocument())
     {
         //Opens the Word template document.
         Stream docStream = File.OpenRead(Path.GetFullPath(@"../../../TOC.docx"));
         document.Open(docStream, FormatType.Docx);
         docStream.Dispose();
         //Edits the TOC field.
         TableOfContent toc = document.Sections[0].Body.Paragraphs[2].Items[0] as TableOfContent;
         //By default, the TOC is generated for 3 levels of heading styles (heading 1 to 3)
         //Here, TOC levels are set for just 2 levels using LowerHeadingLevel
         //and UpperHeadingLevel properties (Heading 1 and Heading 2)
         toc.LowerHeadingLevel = 1;
         toc.UpperHeadingLevel = 2;
         //Hides the page number in TOC.
         toc.IncludePageNumbers = false;
         //Includes the TC fields in TOC heading.
         toc.UseTableEntryFields = true;
         //Updates the table of contents
         document.UpdateTableOfContents();
         //Saves the file in the given path
         docStream = File.Create(Path.GetFullPath(@"../../../TOC-Editing.docx"));
         document.Save(docStream, FormatType.Docx);
         docStream.Dispose();
     }
 }
示例#6
0
        /// <summary>
        /// Finds the last TOC item.
        /// </summary>
        /// <param name="toc"></param>
        /// <returns></returns>
        private static Entity FindLastTOCItem(TableOfContent toc)
        {
            int tocIndex = toc.OwnerParagraph.Items.IndexOf(toc);
            //TOC may contains nested fields and each fields has its owner field end mark
            //so to identify the TOC Field end mark (WFieldMark instance) used the stack.
            Stack <Entity> fieldStack = new Stack <Entity>();

            fieldStack.Push(toc);

            //Finds whether TOC end item is exist in same paragraph.
            for (int i = tocIndex + 1; i < toc.OwnerParagraph.Items.Count; i++)
            {
                Entity item = toc.OwnerParagraph.Items[i];

                if (item is WField)
                {
                    fieldStack.Push(item);
                }
                else if (item is WFieldMark && (item as WFieldMark).Type == FieldMarkType.FieldEnd)
                {
                    if (fieldStack.Count == 1)
                    {
                        fieldStack.Clear();
                        return(item);
                    }
                    else
                    {
                        fieldStack.Pop();
                    }
                }
            }
            return(FindLastItemInTextBody(toc, fieldStack));
        }
示例#7
0
        /// <summary>
        /// Removes the table of contents from Word document.
        /// </summary>
        /// <param name="toc"></param>
        private static void RemoveTableOfContents(TableOfContent toc)
        {
            //Finds the last TOC item.
            Entity lastItem = FindLastTOCItem(toc);

            //TOC field end mark wasn't exist.
            if (lastItem == null)
            {
                return;
            }

            //Inserts the bookmark start before the TOC instance.
            BookmarkStart bkmkStart = new BookmarkStart(toc.Document, "tableOfContent");

            toc.OwnerParagraph.Items.Insert(toc.OwnerParagraph.Items.IndexOf(toc), bkmkStart);

            //Inserts the bookmark end to next of TOC last item.
            BookmarkEnd bkmkEnd   = new BookmarkEnd(toc.Document, "tableOfContent");
            WParagraph  paragraph = lastItem.Owner as WParagraph;

            paragraph.Items.Insert(paragraph.Items.IndexOf(lastItem) + 1, bkmkEnd);

            //Delete all the items from bookmark start to end (TOC items) using Bookmark Navigator.
            DeleteBookmarkContents(bkmkEnd.Name, toc.Document);
        }
        public string GenerateTableOfContentXHTML(TableOfContent tableOfContent)
        {
            StringBuilder textBuilder = new StringBuilder();

            textBuilder.AppendLine(@"<?xml version=""1.0"" encoding=""UTF-8""  standalone=""no""?>");
            textBuilder.AppendLine(@"<!DOCTYPE html>");
            textBuilder.AppendLine(@"<html xmlns=""http://www.w3.org/1999/xhtml"" xmlns:epub=""http://www.idpf.org/2007/ops"">");
            textBuilder.AppendLine(@"<head>");
            textBuilder.AppendLine(@"<title>Table of Contents</title>");
            textBuilder.AppendLine(@"</head>");
            textBuilder.AppendLine(@"<body>");
            textBuilder.AppendLine(@"<section>");
            textBuilder.AppendLine(@"<header><h1>Table of Contents</h1></header>");
            textBuilder.AppendLine(@"<article>");
            textBuilder.AppendLine(@"<nav epub:type=""toc"" id=""toc"">");
            textBuilder.AppendLine(@"<ol>");

            foreach (var node in tableOfContent.Nodes)
            {
                textBuilder.AppendLine($@"<li>");
                textBuilder.AppendLine($@"<a href=""{node.Src}"">{node.Title}</a>");
                textBuilder.AppendLine($"</li>");
            }

            textBuilder.AppendLine("</ol>");
            textBuilder.AppendLine("</nav>");
            textBuilder.AppendLine("</article>");
            textBuilder.AppendLine("</section>");
            textBuilder.AppendLine("</body>");
            textBuilder.AppendLine("</html>");
            return(textBuilder.ToString());
        }
示例#9
0
        static void Main(string[] args)
        {
            //Creates a new Word document
            WordDocument document = new WordDocument();
            //Adds the section into the Word document
            IWSection section  = document.AddSection();
            string    paraText = "AdventureWorks Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company.";
            //Adds the paragraph into the created section
            IWParagraph paragraph = section.AddParagraph();

            //Appends the TOC field with LowerHeadingLevel and UpperHeadingLevel to determines the TOC entries
            paragraph.AppendTOC(1, 3);
            //Adds the section into the Word document
            section = document.AddSection();
            //Adds the paragraph into the created section
            paragraph = section.AddParagraph();
            //Adds the text for the headings
            paragraph.AppendText("First Chapter");
            //Sets a built-in heading style.
            paragraph.ApplyStyle(BuiltinStyle.Heading1);
            //Adds the text into the paragraph
            section.AddParagraph().AppendText(paraText);
            //Adds the section into the Word document
            section = document.AddSection();
            //Adds the paragraph into the created section
            paragraph = section.AddParagraph();
            //Adds the text for the headings
            paragraph.AppendText("Second Chapter");
            //Sets a built-in heading style.
            paragraph.ApplyStyle(BuiltinStyle.Heading2);
            //Adds the text into the paragraph
            section.AddParagraph().AppendText(paraText);
            //Adds the section into the Word document
            section = document.AddSection();
            //Adds the paragraph into the created section
            paragraph = section.AddParagraph();
            //Adds the text into the headings
            paragraph.AppendText("Third Chapter");
            //Sets a built-in heading style
            paragraph.ApplyStyle(BuiltinStyle.Heading3);
            //Adds the text into the paragraph.
            section.AddParagraph().AppendText(paraText);
            //Updates the table of contents
            document.UpdateTableOfContents();
            //Finds the TOC from Word document.
            TableOfContent toc = FindTableOfContent(document);

            //Change tab leader for table of contents in the Word document
            if (toc != null)
            {
                ChangeTabLeaderForTableOfContents(toc, TabLeader.Hyphenated);
            }

            //Saves and closes the Word document
            document.Save("Result.docx");
            document.Close();

            System.Diagnostics.Process.Start("Result.docx");
        }
示例#10
0
 public Epub(string title, CultureInfo culture)
 {
     _title       = title;
     _chapterList = new ChapterList();
     _chapterList.ChapterAdded += OnChapterAdded;
     _content        = new Content(_title, culture.TwoLetterISOLanguageName.ToLower());
     _mimeType       = new MimeType();
     _metaInf        = new MetaInf();
     _tableOfContent = new TableOfContent(_title);
 }
示例#11
0
        public bool Render(TableOfContent toc)
        {
            if (toc == null)
            {
                return(false);
            }

            _renderer.Render(toc, _writer);

            return(true);
        }
        public void ChangeSavedOneToManyReferenceTest()
        {
            Key tableOfContentKey;
            Key item1Key, item2Key, item3Key;

            using (var populateSession = Domain.OpenSession())
                using (var transaction = populateSession.OpenTransaction()) {
                    var tableOfContent = new TableOfContent();
                    var item1          = new TableOfContentItem();
                    var item2          = new TableOfContentItem();
                    var item3          = new TableOfContentItem();
                    tableOfContentKey = tableOfContent.Key;
                    item1Key          = item1.Key;
                    item2Key          = item2.Key;
                    item3Key          = item3.Key;
                    tableOfContent.Items.Add(item1);
                    tableOfContent.Items.Add(item2);
                    tableOfContent.Items.Add(item3);
                    transaction.Complete();
                }

            using (var session = Domain.OpenSession(sessionConfiguration)) {
                var tableOfContent = session.Query.Single <TableOfContent>(tableOfContentKey);
                var item1          = session.Query.Single <TableOfContentItem>(item1Key);
                var item2          = session.Query.Single <TableOfContentItem>(item2Key);
                var item3          = session.Query.Single <TableOfContentItem>(item3Key);
                Assert.That(session.NonPairedReferencesRegistry.RemovedReferencesCount, Is.EqualTo(0));
                Assert.That(session.NonPairedReferencesRegistry.AddedReferencesCount, Is.EqualTo(0));
                Assert.That(ReferenceFinder.GetReferencesTo(tableOfContent).Count(), Is.EqualTo(3));
                Assert.That(ReferenceFinder.GetReferencesTo(item1).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(item2).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(item3).Count(), Is.EqualTo(1));

                var newTableOfContent = new TableOfContent();
                item1.TableOfContent = newTableOfContent;

                Assert.That(session.NonPairedReferencesRegistry.RemovedReferencesCount, Is.EqualTo(0));
                Assert.That(session.NonPairedReferencesRegistry.AddedReferencesCount, Is.EqualTo(0));
                Assert.That(ReferenceFinder.GetReferencesTo(tableOfContent).Count(), Is.EqualTo(2));
                Assert.That(ReferenceFinder.GetReferencesTo(newTableOfContent).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(item1).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(item2).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(item3).Count(), Is.EqualTo(1));

                item2.TableOfContent = null;
                Assert.That(session.NonPairedReferencesRegistry.RemovedReferencesCount, Is.EqualTo(0));
                Assert.That(session.NonPairedReferencesRegistry.AddedReferencesCount, Is.EqualTo(0));
                Assert.That(ReferenceFinder.GetReferencesTo(tableOfContent).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(newTableOfContent).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(item1).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(item2).Count(), Is.EqualTo(0));
                Assert.That(ReferenceFinder.GetReferencesTo(item3).Count(), Is.EqualTo(1));
            }
        }
示例#13
0
 private static void smethod_2(Class581 A_0, CharacterFormat A_1)
 {
     if ((A_0.imethod_1().method_52().Count <= 0) || (A_0.imethod_1().method_53() != FieldCharType.Seperate))
     {
         bool flag = A_0.imethod_1().method_53() == FieldCharType.Begin;
         fieldCharType_0 = FieldCharType.Seperate;
         A_0.imethod_1().method_52().Push(fieldCharType_0);
         ParagraphBase lastChild = A_0.method_13().LastChild as ParagraphBase;
         if (A_0.imethod_1().method_57() != null)
         {
             lastChild = A_0.imethod_1().method_57();
         }
         else if (flag)
         {
             lastChild = new Field(A_0.Interface50.imethod_0());
             A_0.imethod_1().method_54().Push(lastChild as Field);
             A_0.method_9(lastChild);
         }
         if (((lastChild is Field) || (lastChild is TextRange)) && !(lastChild is MergeField))
         {
             if ((lastChild is Field) ? ((lastChild as Field).Type == FieldType.FieldTOC) : false)
             {
                 if (lastChild.Owner == null)
                 {
                     return;
                 }
                 (lastChild as Field).ParseFieldCode((lastChild as Field).Code);
                 TableOfContent content          = new TableOfContent(A_0.Interface50.imethod_0(), A_0.imethod_1().method_57().FormattingString);
                 A_0.Interface50.imethod_0().TOC = content;
                 content.FormattingString = A_0.imethod_1().method_57().FormattingString;
                 A_0.method_13().ChildObjects.Remove(lastChild);
                 A_0.method_9(content);
                 if (A_0.method_13() is Paragraph)
                 {
                     (A_0.method_13() as Paragraph).IsTOCPara = true;
                 }
                 else
                 {
                     (A_0.method_13() as ParagraphBase).OwnerParagraph.IsTOCPara = true;
                 }
                 lastChild = content.TOCField;
             }
             FieldMark mark = new FieldMark(A_0.Interface50.imethod_0(), A_1, FieldMarkType.FieldSeparator);
             A_0.method_9(mark);
             if (lastChild is Field)
             {
                 (lastChild as Field).Separator = mark;
             }
         }
     }
 }
示例#14
0
 static void Main(string[] args)
 {
     using (WordDocument document = new WordDocument())
     {
         document.EnsureMinimal();
         document.LastSection.PageSetup.Margins.All = 72;
         WParagraph para = document.LastParagraph;
         para.AppendText("Essential DocIO - Table of Contents");
         para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
         para.ApplyStyle(BuiltinStyle.Heading4);
         para = document.LastSection.AddParagraph() as WParagraph;
         //Creates the new custom styles.
         WParagraphStyle pStyle1 = (WParagraphStyle)document.AddParagraphStyle("MyStyle1");
         pStyle1.CharacterFormat.FontSize = 18f;
         WParagraphStyle pStyle2 = (WParagraphStyle)document.AddParagraphStyle("MyStyle2");
         pStyle2.CharacterFormat.FontSize = 16f;
         WParagraphStyle pStyle3 = (WParagraphStyle)document.AddParagraphStyle("MyStyle3");
         pStyle3.CharacterFormat.FontSize = 14f;
         para = document.LastSection.AddParagraph() as WParagraph;
         //Insert TOC field in the Word document.
         TableOfContent toc = para.AppendTOC(1, 3);
         //Sets the Heading Styles to false, to define custom levels for TOC.
         toc.UseHeadingStyles = false;
         //Sets the TOC level style which determines; based on which the TOC should be created.
         toc.SetTOCLevelStyle(1, "MyStyle1");
         toc.SetTOCLevelStyle(2, "MyStyle2");
         toc.SetTOCLevelStyle(3, "MyStyle3");
         //Adds content to the Word document with custom styles.
         WSection   section = document.LastSection;
         WParagraph newPara = section.AddParagraph() as WParagraph;
         newPara.AppendBreak(BreakType.PageBreak);
         AddHeading(section, "MyStyle1", "Document with custom styles", "This is the 1st custom style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can insert TOC field in a word document. It can refresh or update TOC field by using UpdateTableOfContents method. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");
         AddHeading(section, "MyStyle2", "Section 1", "This is the 2nd custom style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");
         AddHeading(section, "MyStyle3", "Paragraph 1", "This is the 3rd custom style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");
         AddHeading(section, "MyStyle3", "Paragraph 2", "This is the 3rd custom style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");
         AddHeading(section, "Normal", "Paragraph with normal", "This is the paragraph with normal style. This demonstrates the paragraph with outline level 4 and normal style. This can be attained by formatting outline level of the paragraph.");
         //Adds a new section to the Word document.
         section = document.AddSection() as WSection;
         section.PageSetup.Margins.All = 72;
         section.BreakCode             = SectionBreakCode.NewPage;
         AddHeading(section, "MyStyle2", "Section 2", "This is the 2nd custom style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");
         AddHeading(section, "MyStyle3", "Paragraph 1", "This is the 3rd custom style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");
         AddHeading(section, "MyStyle3", "Paragraph 2", "This is the 3rd custom style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");
         //Updates the table of contents.
         document.UpdateTableOfContents();
         //Saves the file in the given path
         Stream docStream = File.Create(Path.GetFullPath(@"../../../TOC-custom-style.docx"));
         document.Save(docStream, FormatType.Docx);
         docStream.Dispose();
     }
 }
示例#15
0
 public void Render(TableOfContent toc, IPageWriter writer)
 {
     foreach (var page in toc.Pages)
     {
         var template = _provider.GetTemplate(page.Content);
         template.Match(
             some: c =>
         {
             var text = c.Apply(page.Content).ValueOr(string.Empty);
             writer.Write(text, page, toc.Root);
         },
             none: () => { }
             );
     }
 }
示例#16
0
 static void Main(string[] args)
 {
     using (WordDocument document = new WordDocument())
     {
         //Opens the Word template document.
         Stream docStream = File.OpenRead(Path.GetFullPath(@"../../../TOC.docx"));
         document.Open(docStream, FormatType.Docx);
         docStream.Dispose();
         //Removes the TOC field.
         TableOfContent toc = document.Sections[0].Body.Paragraphs[2].Items[0] as TableOfContent;
         RemoveTableOfContents(toc);
         //Saves the file in the given path
         docStream = File.Create(Path.GetFullPath(@"../../../Sample.docx"));
         document.Save(docStream, FormatType.Docx);
         docStream.Dispose();
     }
 }
示例#17
0
 public ActionResult Upload(TableOfContent obj)
 {
     if (ModelState.IsValid)
     {
         string xmlFileName = "";
         if (obj.XMLFilePath != null)
         {
             // 1. Upload xml file to server
             xmlFileName = Server.MapPath(XMLPath + obj.XMLFilePath.FileName);
             obj.XMLFilePath.SaveAs(xmlFileName);
             //Paser xml file from server file
             listOfLevel1FromXMLFile = XMLHanlder.ReadXML(xmlFileName, Server.MapPath(HTMLPath), obj.SourceFolder);
             // synchronize with DB
             helpOnlineDB.UpdateIndexTopicToZero();
             helpOnlineDB.UpdateDBWithXML(listOfLevel1FromXMLFile, Server.MapPath(HTMLPath), obj.SourceFolder);
             XMLHanlder.UploadImageFiles(obj.SourceFolder);
             return(RedirectToAction("UploadSuccess"));
         }
     }
     return(View());
 }
示例#18
0
 static void Main(string[] args)
 {
     using (WordDocument document = new WordDocument())
     {
         document.EnsureMinimal();
         document.LastSection.PageSetup.Margins.All = 72;
         WParagraph para = document.LastParagraph;
         para.AppendText("Essential DocIO - Table of Contents");
         para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
         para.ApplyStyle(BuiltinStyle.Heading4);
         para = document.LastSection.AddParagraph() as WParagraph;
         para = document.LastSection.AddParagraph() as WParagraph;
         //Insert TOC field in the Word document.
         TableOfContent toc = para.AppendTOC(1, 3);
         //Sets the heading levels 1 to 3, to include in TOC.
         toc.LowerHeadingLevel = 1;
         toc.UpperHeadingLevel = 3;
         //Adds content to the Word document with built-in heading styles.
         WSection   section = document.LastSection;
         WParagraph newPara = section.AddParagraph() as WParagraph;
         newPara.AppendBreak(BreakType.PageBreak);
         AddHeading(section, BuiltinStyle.Heading1, "Document with built-in heading styles", "This is the built-in heading 1 style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can insert TOC field in a word document. It can refresh or update TOC field by using UpdateTableOfContents method. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");
         AddHeading(section, BuiltinStyle.Heading2, "Section 1", "This is the built-in heading 2 style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");
         AddHeading(section, BuiltinStyle.Heading3, "Paragraph 1", "This is the built-in heading 3 style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");
         AddHeading(section, BuiltinStyle.Heading3, "Paragraph 2", "This is the built-in heading 3 style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");
         //Adds a new section to the Word document.
         section = document.AddSection() as WSection;
         section.PageSetup.Margins.All = 72;
         section.BreakCode             = SectionBreakCode.NewPage;
         AddHeading(section, BuiltinStyle.Heading2, "Section 2", "This is the built-in heading 2 style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");
         AddHeading(section, BuiltinStyle.Heading3, "Paragraph 1", "This is the built-in heading 3 style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");
         AddHeading(section, BuiltinStyle.Heading3, "Paragraph 2", "This is the built-in heading 3 style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");
         //Updates the table of contents.
         document.UpdateTableOfContents();
         //Saves the file in the given path
         Stream docStream = File.Create(Path.GetFullPath(@"../../../TOC-creation.docx"));
         document.Save(docStream, FormatType.Docx);
         docStream.Dispose();
     }
 }
示例#19
0
        /// <summary>
        /// Change tab leader for table of contents in the Word document.
        /// </summary>
        /// <param name="toc"></param>
        private static void ChangeTabLeaderForTableOfContents(TableOfContent toc, TabLeader tabLeader)
        {
            //Inserts the bookmark start before the TOC instance.
            BookmarkStart bkmkStart = new BookmarkStart(toc.Document, "tableOfContent");

            toc.OwnerParagraph.Items.Insert(toc.OwnerParagraph.Items.IndexOf(toc), bkmkStart);

            Entity lastItem = FindLastTOCItem(toc);

            //Insert the bookmark end to next of TOC last item.
            BookmarkEnd bkmkEnd   = new BookmarkEnd(toc.Document, "tableOfContent");
            WParagraph  paragraph = lastItem.Owner as WParagraph;

            paragraph.Items.Insert(paragraph.Items.IndexOf(lastItem) + 1, bkmkEnd);

            //Creates the bookmark navigator instance to access the bookmark
            BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(toc.Document);

            //Moves the virtual cursor to the location before the end of the bookmark "tableOfContent"
            bookmarkNavigator.MoveToBookmark("tableOfContent");
            //Gets the bookmark content
            TextBodyPart part = bookmarkNavigator.GetBookmarkContent();

            //Iterates the items from the bookmark to change the spacing in the table of content
            for (int i = 0; i < part.BodyItems.Count; i++)
            {
                paragraph = part.BodyItems[i] as WParagraph;
                //Sets the tab leader
                if (paragraph.ParagraphFormat.Tabs.Count != 0)
                {
                    paragraph.ParagraphFormat.Tabs[0].TabLeader = tabLeader;
                }
            }

            //Remove the bookmark which we add to get the paragraphs in the table of contents
            Bookmark bookmark = toc.Document.Bookmarks.FindByName("tableOfContent");

            toc.Document.Bookmarks.Remove(bookmark);
        }
 public string RenderTableOfContent(TableOfContent tableDeMatiere)
 {
     throw new NotImplementedException();
 }
示例#21
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                WordDocument doc = new WordDocument();
                doc.EnsureMinimal();

                WParagraph para = doc.LastParagraph;
                para.AppendText("Essential DocIO - Table of Contents");
                para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                para.ApplyStyle(BuiltinStyle.Heading4);

                para = doc.LastSection.AddParagraph() as WParagraph;
                para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                para.ApplyStyle(BuiltinStyle.Heading4);

                if (!this.checkBox6.Checked)
                {
                    para.AppendText("Select TOC and press F9 to update the Table of Contents").CharacterFormat.HighlightColor = Color.Yellow;
                }

                para = doc.LastSection.AddParagraph() as WParagraph;
                string title = this.textBox1.Text + "\n";
                para.AppendText(title);
                para.ApplyStyle(BuiltinStyle.Heading4);

                //Insert TOC
                TableOfContent toc = para.AppendTOC(1, 3);

                para.ApplyStyle(BuiltinStyle.Heading4);
                //Apply built-in paragraph formatting
                WSection section = doc.LastSection;
                // Set Margin of the document
                section.PageSetup.Margins.All = 72;
                if (radioButton1.Checked)
                {
                    #region Default Styles
                    WParagraph newPara = section.AddParagraph() as WParagraph;
                    newPara = section.AddParagraph() as WParagraph;
                    newPara.AppendBreak(BreakType.PageBreak);
                    WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange;
                    newPara.ApplyStyle(BuiltinStyle.Heading1);
                    newPara = section.AddParagraph() as WParagraph;
                    newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");

                    section.AddParagraph();
                    newPara = section.AddParagraph() as WParagraph;
                    text    = newPara.AppendText("Section1") as WTextRange;
                    newPara.ApplyStyle(BuiltinStyle.Heading2);
                    newPara = section.AddParagraph() as WParagraph;
                    newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

                    section.AddParagraph();
                    newPara = section.AddParagraph() as WParagraph;
                    text    = newPara.AppendText("Paragraph1") as WTextRange;
                    newPara.ApplyStyle(BuiltinStyle.Heading3);
                    newPara = section.AddParagraph() as WParagraph;
                    newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");

                    section.AddParagraph();
                    newPara = section.AddParagraph() as WParagraph;
                    text    = newPara.AppendText("Paragraph2") as WTextRange;
                    newPara.ApplyStyle(BuiltinStyle.Heading3);
                    newPara = section.AddParagraph() as WParagraph;
                    newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");

                    section.AddParagraph();
                    section           = doc.AddSection() as WSection;
                    section.BreakCode = SectionBreakCode.NewPage;
                    newPara           = section.AddParagraph() as WParagraph;
                    text = newPara.AppendText("Section2") as WTextRange;
                    newPara.ApplyStyle(BuiltinStyle.Heading2);
                    newPara = section.AddParagraph() as WParagraph;
                    newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

                    section.AddParagraph();
                    newPara = section.AddParagraph() as WParagraph;
                    text    = newPara.AppendText("Paragraph1") as WTextRange;
                    newPara.ApplyStyle(BuiltinStyle.Heading3);
                    newPara = section.AddParagraph() as WParagraph;
                    newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");

                    section.AddParagraph();
                    newPara = section.AddParagraph() as WParagraph;
                    text    = newPara.AppendText("Paragraph2") as WTextRange;
                    newPara.ApplyStyle(BuiltinStyle.Heading3);
                    newPara = section.AddParagraph() as WParagraph;
                    newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");

                    #endregion
                }
                else
                {
                    #region Custom styles

                    //Custom styles.
                    WParagraphStyle pStyle1 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle1");
                    WParagraphStyle pStyle2 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle2");
                    WParagraphStyle pStyle3 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle3");

                    //Set the Heading Styles to false in order to define custom levels to TOC.
                    toc.UseHeadingStyles = false;

                    //Set the TOC level style which determines; based on which the TOC should be created.
                    toc.SetTOCLevelStyle(1, "MyStyle1");
                    toc.SetTOCLevelStyle(2, "MyStyle2");
                    toc.SetTOCLevelStyle(3, "MyStyle3");
                    section = doc.AddSection() as WSection;

                    pStyle1.CharacterFormat.FontName = "Cambria";
                    pStyle1.CharacterFormat.FontSize = 30f;

                    para = section.AddParagraph() as WParagraph;

                    WTextRange text = para.AppendText("Document with Custom Styles") as WTextRange;
                    para.ApplyStyle("MyStyle1");
                    para = doc.LastSection.AddParagraph() as WParagraph;
                    para.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");

                    pStyle2.CharacterFormat.FontName = "Cambria";
                    pStyle2.CharacterFormat.FontSize = 20f;

                    doc.LastSection.AddParagraph();

                    para = doc.LastSection.AddParagraph() as WParagraph;
                    text = para.AppendText("Section1") as WTextRange;
                    para.ApplyStyle("MyStyle2");
                    para = doc.LastSection.AddParagraph() as WParagraph;
                    para.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

                    pStyle3.CharacterFormat.FontName = "Cambria";
                    pStyle3.CharacterFormat.FontSize = 14f;

                    doc.LastSection.AddParagraph();

                    para = doc.LastSection.AddParagraph() as WParagraph;
                    text = para.AppendText("Section2") as WTextRange;
                    para.ApplyStyle("MyStyle3");
                    para = doc.LastSection.AddParagraph() as WParagraph;
                    para.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

                    #endregion
                }
                if (this.numericUpDown2.Value < this.numericUpDown1.Value)
                {
                    MessageBoxAdv.Show("Not a valid heading level range. UpperHeadingLevel must be greater than LowerHeadingLevel");
                }
                else
                {
                    toc.IncludePageNumbers    = checkBox1.Checked;
                    toc.RightAlignPageNumbers = checkBox2.Checked;
                    toc.UseHyperlinks         = checkBox3.Checked;
                    toc.LowerHeadingLevel     = Convert.ToInt32(this.numericUpDown1.Value);
                    toc.UpperHeadingLevel     = Convert.ToInt32(this.numericUpDown2.Value);
                    //Right click text. Select Paragraph option. Set OutlineLevel. Update TOC toc see the text added in TOC.
                    toc.UseOutlineLevels = this.checkBox4.Checked;
                    //Select the text that should be marked as Table of contents.
                    //Press ALT+SHIFT+O. A dialog box will appear with options to enter the text, select the table identifier and level.
                    //Choose the table identifier and level for the test and click �Mark�. Update TOC toc see the text added in TOC.
                    //Sets the Table Identifier if necessary.
                    //toc.TableID = "B";
                    toc.UseTableEntryFields = this.checkBox5.Checked;
                    //Updates the table of contents.
                    if (this.checkBox6.Checked)
                    {
                        doc.UpdateTableOfContents();
                    }
                    //Save as doc format
                    if (wordDocRadioBtn.Checked)
                    {
                        //Saving the document to disk.
                        doc.Save("Sample.doc");

                        //Message box confirmation to view the created document.
                        if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.doc")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Sample.doc");
#endif
                            //Exit
                            this.Close();
                        }
                    }
                    //Save as docx format
                    else if (wordDocxRadioBtn.Checked)
                    {
                        //Saving the document as .docx
                        doc.Save("Sample.docx", FormatType.Docx);
                        //Message box confirmation to view the created document.
                        if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                        {
                            try
                            {
                                //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                                System.Diagnostics.Process process = new System.Diagnostics.Process();
                                process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx")
                                {
                                    UseShellExecute = true
                                };
                                process.Start();
#else
                                System.Diagnostics.Process.Start("Sample.docx");
#endif
                                //Exit
                                this.Close();
                            }
                            catch (Win32Exception ex)
                            {
                                MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                                Console.WriteLine(ex.ToString());
                            }
                        }
                    }
                    //Save as pdf format
                    else if (pdfRadioBtn.Checked)
                    {
                        DocToPDFConverter converter = new DocToPDFConverter();
                        //Convert word document into PDF document
                        PdfDocument pdfDoc = converter.ConvertToPDF(doc);
                        //Save the pdf file
                        pdfDoc.Save("Sample.pdf");
                        //Message box confirmation to view the created document.
                        if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                        {
                            try
                            {
#if NETCORE
                                System.Diagnostics.Process process = new System.Diagnostics.Process();
                                process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf")
                                {
                                    UseShellExecute = true
                                };
                                process.Start();
#else
                                System.Diagnostics.Process.Start("Sample.pdf");
#endif
                                //Exit
                                this.Close();
                            }
                            catch (Exception ex)
                            {
                                MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                                Console.WriteLine(ex.ToString());
                            }
                        }
                    }
                    else
                    {
                        // Exit
                        this.Close();
                    }
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
示例#22
0
        public ActionResult TableofContent(string Group1, string UpdateTOC)
        {
            if (Group1 == null)
            {
                return(View());
            }
            WordDocument doc = new WordDocument();

            doc.EnsureMinimal();

            WParagraph para = doc.LastParagraph;

            para.AppendText("Essential DocIO - Table of Contents");
            para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            para.ApplyStyle(BuiltinStyle.Heading4);

            para = doc.LastSection.AddParagraph() as WParagraph;
            para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            para.ApplyStyle(BuiltinStyle.Heading4);

            if (UpdateTOC != "Update")
            {
                para.AppendText("Select TOC and press F9 to update the Table of Contents").CharacterFormat.HighlightColor = Color.Yellow;
            }

            para = doc.LastSection.AddParagraph() as WParagraph;

            //Insert TOC
            TableOfContent toc = para.AppendTOC(1, 3);

            para.ApplyStyle(BuiltinStyle.Heading4);

            //Apply built-in paragraph formatting
            WSection section = doc.LastSection;

            #region Default Styles
            WParagraph newPara = section.AddParagraph() as WParagraph;
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendBreak(BreakType.PageBreak);
            WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading1);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Section1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading2);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");

            section.AddParagraph();
            section           = doc.AddSection() as WSection;
            section.BreakCode = SectionBreakCode.NewPage;
            newPara           = section.AddParagraph() as WParagraph;
            text = newPara.AppendText("Section2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading2);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");
            #endregion

            toc.IncludePageNumbers    = true;
            toc.RightAlignPageNumbers = true;
            toc.UseHyperlinks         = true;
            toc.LowerHeadingLevel     = 1;
            toc.UpperHeadingLevel     = 3;

            toc.UseOutlineLevels = true;

            //Updates the table of contents.
            if (UpdateTOC == "Update")
            {
                doc.UpdateTableOfContents();
            }

            //Save as .doc format
            if (Group1 == "WordDoc")
            {
                return(doc.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
            }
            //Save as .docx format
            else if (Group1 == "WordDocx")
            {
                return(doc.ExportAsActionResult("Sample.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
            }
            // Save as WordML(.xml) format
            else if (Group1 == "WordML")
            {
                return(doc.ExportAsActionResult("Sample.xml", FormatType.WordML, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
            }
            //Save as .pdf format
            else if (Group1 == "Pdf")
            {
                DocToPDFConverter converter = new DocToPDFConverter();
                PdfDocument       pdfDoc    = converter.ConvertToPDF(doc);

                return(pdfDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
            return(View());
        }
        public ActionResult TableofContents(string Group1, string UpdateTOC)
        {
            if (Group1 == null)
            {
                return(View());
            }
            WordDocument doc = new WordDocument();

            doc.EnsureMinimal();

            WParagraph para = doc.LastParagraph;

            para.AppendText("Essential DocIO - Table of Contents");
            para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            para.ApplyStyle(BuiltinStyle.Heading4);

            para = doc.LastSection.AddParagraph() as WParagraph;
            para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            para.ApplyStyle(BuiltinStyle.Heading4);

            if (UpdateTOC != "Update")
            {
                para.AppendText("Select TOC and press F9 to update the Table of Contents").CharacterFormat.HighlightColor = Syncfusion.Drawing.Color.Yellow;
            }

            para = doc.LastSection.AddParagraph() as WParagraph;

            //Insert TOC
            TableOfContent toc = para.AppendTOC(1, 3);

            para.ApplyStyle(BuiltinStyle.Heading4);

            //Apply built-in paragraph formatting
            WSection section = doc.LastSection;

            #region Default Styles
            WParagraph newPara = section.AddParagraph() as WParagraph;
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendBreak(BreakType.PageBreak);
            WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading1);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Section1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading2);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");

            section.AddParagraph();
            section           = doc.AddSection() as WSection;
            section.BreakCode = SectionBreakCode.NewPage;
            newPara           = section.AddParagraph() as WParagraph;
            text = newPara.AppendText("Section2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading2);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");
            #endregion
            toc.IncludePageNumbers    = true;
            toc.RightAlignPageNumbers = true;
            toc.UseHyperlinks         = true;
            toc.LowerHeadingLevel     = 1;
            toc.UpperHeadingLevel     = 3;

            toc.UseOutlineLevels = true;

            //Updates the table of contents.
            if (UpdateTOC == "Update")
            {
                doc.UpdateTableOfContents();
            }

            #region Document SaveOption
            string       filename    = "";
            string       contenttype = "";
            MemoryStream ms          = new MemoryStream();
            //Save as .docx format
            if (Group1 == "WordDocx")
            {
                filename    = "Table of Contents.docx";
                contenttype = "application/vnd.ms-word.document.12";
                doc.Save(ms, FormatType.Docx);
            }
            // Save as .doc format
            else if (Group1 == "WordDoc")
            {
                filename    = "Table of Contents.doc";
                contenttype = "application/msword";
                doc.Save(ms, FormatType.Doc);
            }
            //Save as .xml format
            else if (Group1 == "WordML")
            {
                filename    = "Table of Contents.xml";
                contenttype = "application/msword";
                doc.Save(ms, FormatType.WordML);
            }
            //Save as .pdf format
            else if (Group1 == "Pdf")
            {
                filename    = "Table of Contents.pdf";
                contenttype = "application/pdf";
                Syncfusion.DocIORenderer.DocIORenderer renderer = new Syncfusion.DocIORenderer.DocIORenderer();
                Syncfusion.Pdf.PdfDocument             pdfDoc   = renderer.ConvertToPDF(doc);
                pdfDoc.Save(ms);
                pdfDoc.Close();
            }
            #endregion Document SaveOption
            doc.Close();
            ms.Position = 0;
            return(File(ms, contenttype, filename));
        }
        public void RemoveEntityToEntitySetTest()
        {
            Key tableWithItemsKey;
            Key item1Key, item2Key;
            Key book1Key, book2Key;
            Key author1Key, author2Key;

            using (var populateSession = Domain.OpenSession())
                using (var transaction = populateSession.OpenTransaction()) {
                    var tableWithItems = new TableOfContent();
                    tableWithItemsKey = tableWithItems.Key;
                    var item1 = new TableOfContentItem();
                    var item2 = new TableOfContentItem();
                    item1Key = item1.Key;
                    item2Key = item2.Key;
                    tableWithItems.Items.Add(item1);
                    tableWithItems.Items.Add(item2);

                    var book1 = new Book();
                    book1Key = book1.Key;
                    var book2 = new Book();
                    book2Key = book2.Key;

                    var author1 = new Author();
                    author1Key = author1.Key;
                    var author2 = new Author();
                    author2Key = author2.Key;

                    author1.Books.Add(book1);
                    author1.Books.Add(book2);
                    author2.Books.Add(book1);
                    author2.Books.Add(book2);

                    transaction.Complete();
                }

            using (var session = Domain.OpenSession(sessionConfiguration)) {
                var tableWithItems = session.Query.Single <TableOfContent>(tableWithItemsKey);
                var item1          = session.Query.Single <TableOfContentItem>(item1Key);
                var item2          = session.Query.Single <TableOfContentItem>(item2Key);
                var item3          = new TableOfContentItem();
                tableWithItems.Items.Add(item3);

                Assert.That(session.NonPairedReferencesRegistry.RemovedReferencesCount, Is.EqualTo(0));
                Assert.That(session.NonPairedReferencesRegistry.AddedReferencesCount, Is.EqualTo(0));
                Assert.That(ReferenceFinder.GetReferencesTo(item1).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(item2).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(item3).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(tableWithItems).Count(), Is.EqualTo(3));

                tableWithItems.Items.Remove(item3);
                tableWithItems.Items.Remove(item2);
                Assert.That(session.NonPairedReferencesRegistry.RemovedReferencesCount, Is.EqualTo(0));
                Assert.That(session.NonPairedReferencesRegistry.AddedReferencesCount, Is.EqualTo(0));
                Assert.That(ReferenceFinder.GetReferencesTo(item1).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(item2).Count(), Is.EqualTo(0));
                Assert.That(ReferenceFinder.GetReferencesTo(item3).Count(), Is.EqualTo(0));
                Assert.That(ReferenceFinder.GetReferencesTo(tableWithItems).Count(), Is.EqualTo(1));

                var oldBook1 = session.Query.Single <Book>(book1Key);
                var oldBook2 = session.Query.Single <Book>(book2Key);
                var newBook  = new Book();

                var oldAutor1 = session.Query.Single <Author>(author1Key);
                var oldAutor2 = session.Query.Single <Author>(author2Key);
                var newAuthor = new Author();

                newAuthor.Books.Add(oldBook1);
                newAuthor.Books.Add(oldBook2);
                newAuthor.Books.Add(newBook);

                newBook.Authors.Add(oldAutor1);
                newBook.Authors.Add(oldAutor2);

                Assert.That(ReferenceFinder.GetReferencesTo(oldBook1).Count(), Is.EqualTo(3));
                Assert.That(ReferenceFinder.GetReferencesTo(oldBook2).Count(), Is.EqualTo(3));
                Assert.That(ReferenceFinder.GetReferencesTo(oldAutor1).Count(), Is.EqualTo(3));
                Assert.That(ReferenceFinder.GetReferencesTo(oldAutor2).Count(), Is.EqualTo(3));
                Assert.That(ReferenceFinder.GetReferencesTo(newBook).Count(), Is.EqualTo(3));
                Assert.That(ReferenceFinder.GetReferencesTo(newAuthor).Count(), Is.EqualTo(3));

                oldAutor1.Books.Remove(oldBook1);
                Assert.That(ReferenceFinder.GetReferencesTo(oldBook1).Count(), Is.EqualTo(2));
                Assert.That(ReferenceFinder.GetReferencesTo(oldBook2).Count(), Is.EqualTo(3));
                Assert.That(ReferenceFinder.GetReferencesTo(oldAutor1).Count(), Is.EqualTo(2));
                Assert.That(ReferenceFinder.GetReferencesTo(oldAutor2).Count(), Is.EqualTo(3));
                Assert.That(ReferenceFinder.GetReferencesTo(newBook).Count(), Is.EqualTo(3));
                Assert.That(ReferenceFinder.GetReferencesTo(newAuthor).Count(), Is.EqualTo(3));

                oldBook2.Authors.Remove(oldAutor2);
                Assert.That(ReferenceFinder.GetReferencesTo(oldBook1).Count(), Is.EqualTo(2));
                Assert.That(ReferenceFinder.GetReferencesTo(oldBook2).Count(), Is.EqualTo(2));
                Assert.That(ReferenceFinder.GetReferencesTo(oldAutor1).Count(), Is.EqualTo(2));
                Assert.That(ReferenceFinder.GetReferencesTo(oldAutor2).Count(), Is.EqualTo(2));
                Assert.That(ReferenceFinder.GetReferencesTo(newBook).Count(), Is.EqualTo(3));
                Assert.That(ReferenceFinder.GetReferencesTo(newAuthor).Count(), Is.EqualTo(3));

                oldAutor1.Books.Remove(newBook);
                newBook.Authors.Remove(oldAutor2);
                Assert.That(ReferenceFinder.GetReferencesTo(oldBook1).Count(), Is.EqualTo(2));
                Assert.That(ReferenceFinder.GetReferencesTo(oldBook2).Count(), Is.EqualTo(2));
                Assert.That(ReferenceFinder.GetReferencesTo(oldAutor1).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(oldAutor2).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(newBook).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(newAuthor).Count(), Is.EqualTo(3));

                newBook.Authors.Remove(newAuthor);
                Assert.That(ReferenceFinder.GetReferencesTo(oldBook1).Count(), Is.EqualTo(2));
                Assert.That(ReferenceFinder.GetReferencesTo(oldBook2).Count(), Is.EqualTo(2));
                Assert.That(ReferenceFinder.GetReferencesTo(oldAutor1).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(oldAutor2).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(newBook).Count(), Is.EqualTo(0));
                Assert.That(ReferenceFinder.GetReferencesTo(newAuthor).Count(), Is.EqualTo(2));
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            WordDocument doc = new WordDocument();

            doc.EnsureMinimal();

            WParagraph para = doc.LastParagraph;

            para.AppendText("Essential DocIO - Table of Contents");
            para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            para.ApplyStyle(BuiltinStyle.Heading4);

            para = doc.LastSection.AddParagraph() as WParagraph;
            para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            para.ApplyStyle(BuiltinStyle.Heading4);

            if (!this.CheckBox7.Checked)
            {
                para.AppendText("Select TOC and press F9 to update the Table of Contents").CharacterFormat.HighlightColor = Color.Yellow;
            }

            para = doc.LastSection.AddParagraph() as WParagraph;
            string title = this.TextBox1.Text + "\n";

            para.AppendText(title);
            para.ApplyStyle(BuiltinStyle.Heading4);

            //Insert TOC
            TableOfContent toc = para.AppendTOC(1, 3);

            para.ApplyStyle(BuiltinStyle.Heading4);
            //Apply built-in paragraph formatting
            WSection section = doc.LastSection;

            if (this.RadioButton1.Checked)
            {
                #region Default Styles
                WParagraph newPara = section.AddParagraph() as WParagraph;
                newPara = section.AddParagraph() as WParagraph;
                newPara.AppendBreak(BreakType.PageBreak);
                WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange;
                newPara.ApplyStyle(BuiltinStyle.Heading1);
                newPara = section.AddParagraph() as WParagraph;
                newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");

                section.AddParagraph();
                newPara = section.AddParagraph() as WParagraph;
                text    = newPara.AppendText("Section1") as WTextRange;
                newPara.ApplyStyle(BuiltinStyle.Heading2);
                newPara = section.AddParagraph() as WParagraph;
                newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

                section.AddParagraph();
                newPara = section.AddParagraph() as WParagraph;
                text    = newPara.AppendText("Paragraph1") as WTextRange;
                newPara.ApplyStyle(BuiltinStyle.Heading3);
                newPara = section.AddParagraph() as WParagraph;
                newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");

                section.AddParagraph();
                newPara = section.AddParagraph() as WParagraph;
                text    = newPara.AppendText("Paragraph2") as WTextRange;
                newPara.ApplyStyle(BuiltinStyle.Heading3);
                newPara = section.AddParagraph() as WParagraph;
                newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");

                section.AddParagraph();
                section           = doc.AddSection() as WSection;
                section.BreakCode = SectionBreakCode.NewPage;
                newPara           = section.AddParagraph() as WParagraph;
                text = newPara.AppendText("Section2") as WTextRange;
                newPara.ApplyStyle(BuiltinStyle.Heading2);
                newPara = section.AddParagraph() as WParagraph;
                newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

                section.AddParagraph();
                newPara = section.AddParagraph() as WParagraph;
                text    = newPara.AppendText("Paragraph1") as WTextRange;
                newPara.ApplyStyle(BuiltinStyle.Heading3);
                newPara = section.AddParagraph() as WParagraph;
                newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");

                section.AddParagraph();
                newPara = section.AddParagraph() as WParagraph;
                text    = newPara.AppendText("Paragraph2") as WTextRange;
                newPara.ApplyStyle(BuiltinStyle.Heading3);
                newPara = section.AddParagraph() as WParagraph;
                newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");
                #endregion
            }
            else
            {
                #region Custom styles
                //Custom styles.
                WParagraphStyle pStyle1 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle1");
                WParagraphStyle pStyle2 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle2");
                WParagraphStyle pStyle3 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle3");

                //Set the Heading Styles to false in order to define custom levels to TOC.
                toc.UseHeadingStyles = false;

                //Set the TOC level style which determines; based on which the TOC should be created.
                toc.SetTOCLevelStyle(1, "MyStyle1");
                toc.SetTOCLevelStyle(2, "MyStyle2");
                toc.SetTOCLevelStyle(3, "MyStyle3");
                section = doc.AddSection() as WSection;

                pStyle1.CharacterFormat.FontName = "Cambria";
                pStyle1.CharacterFormat.FontSize = 30f;

                para = section.AddParagraph() as WParagraph;

                WTextRange text = para.AppendText("Document with Custom Styles") as WTextRange;
                para.ApplyStyle("MyStyle1");
                para = doc.LastSection.AddParagraph() as WParagraph;
                para.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");

                pStyle2.CharacterFormat.FontName = "Cambria";
                pStyle2.CharacterFormat.FontSize = 20f;

                doc.LastSection.AddParagraph();

                para = doc.LastSection.AddParagraph() as WParagraph;
                text = para.AppendText("Section1") as WTextRange;
                para.ApplyStyle("MyStyle2");
                para = doc.LastSection.AddParagraph() as WParagraph;
                para.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

                pStyle3.CharacterFormat.FontName = "Cambria";
                pStyle3.CharacterFormat.FontSize = 14f;

                doc.LastSection.AddParagraph();

                para = doc.LastSection.AddParagraph() as WParagraph;
                text = para.AppendText("Section2") as WTextRange;
                para.ApplyStyle("MyStyle3");
                para = doc.LastSection.AddParagraph() as WParagraph;
                para.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");
                #endregion
            }
            if (Convert.ToInt32(this.DropDownList2.Text) < Convert.ToInt32(this.DropDownList1.Text))
            {
                Response.Write("Not a valid heading level range. UpperHeadingLevel must be greater than LowerHeadingLevel");
            }
            else
            {
                toc.IncludePageNumbers    = this.CheckBox2.Checked;
                toc.RightAlignPageNumbers = this.CheckBox3.Checked;
                toc.UseHyperlinks         = this.CheckBox4.Checked;
                toc.LowerHeadingLevel     = Convert.ToInt32(this.DropDownList1.Text);
                toc.UpperHeadingLevel     = Convert.ToInt32(this.DropDownList2.Text);

                //Used to set levels for a word or paragraph through OutLine Levels
                //Right click text. Select Paragraph option. Set OutlineLevel. Update TOC toc see the text added in TOC.
                toc.UseOutlineLevels = this.CheckBox5.Checked;

                //Used to set levels for a word or paragraph through Table Entry Fields
                //Select the text that should be marked as Table of contents.
                //Press ALT+SHIFT+O. A dialog box will appear with options to enter the text, select the table identifier and level.
                //Choose the table identifier and level for the test and click �Mark�. Update TOC toc see the text added in TOC.
                //Sets the Table Identifier if necessary.
                //toc.TableID = "B";
                toc.UseTableEntryFields = this.CheckBox6.Checked;
                //Updates the table of contents.
                if (this.CheckBox7.Checked)
                {
                    doc.UpdateTableOfContents();
                }

                if (rdButtonDoc.Checked)
                {
                    //Save as .doc format
                    doc.Save("Sample.doc", FormatType.Doc, Response, HttpContentDisposition.Attachment);
                }
                //Save as .docx format
                else if (rdButtonDocx.Checked)
                {
                    try
                    {
                        doc.Save("Sample.docx", FormatType.Docx, Response, HttpContentDisposition.Attachment);
                    }
                    catch (Win32Exception ex)
                    {
                        Response.Write("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }
                //Save as WordML(.xml) format
                if (rdButtonWordML.Checked)
                {
                    try
                    {
                        doc.Save("Sample.xml", FormatType.WordML, Response, HttpContentDisposition.Attachment);
                    }
                    catch (Win32Exception ex)
                    {
                        Response.Write("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }
                //Save as .pdf format
                else if (rdButtonPdf.Checked)
                {
                    try
                    {
                        DocToPDFConverter converter = new DocToPDFConverter();
                        PdfDocument       pdfDoc    = converter.ConvertToPDF(doc);

                        pdfDoc.Save("Sample.pdf", Response, HttpReadType.Save);
                    }
                    catch (Win32Exception ex)
                    {
                        Response.Write("PDF Viewer is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
        }
        void OnButtonClicked(object sender, EventArgs e)
        {
            WordDocument doc = new WordDocument();

            doc.EnsureMinimal();

            WParagraph para = doc.LastParagraph;

            para.AppendText("Essential DocIO - Table of Contents");
            para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            para.ApplyStyle(BuiltinStyle.Heading4);

            para = doc.LastSection.AddParagraph() as WParagraph;
            para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            para.ApplyStyle(BuiltinStyle.Heading4);

            para = doc.LastSection.AddParagraph() as WParagraph;

            //Insert TOC
            TableOfContent toc = para.AppendTOC(1, 3);

            para.ApplyStyle(BuiltinStyle.Heading4);

            //Apply built-in paragraph formatting
            WSection section = doc.LastSection;

            #region Default Styles
            WParagraph newPara = section.AddParagraph() as WParagraph;
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendBreak(BreakType.PageBreak);
            WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading1);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Section1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading2);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");

            section.AddParagraph();
            section           = doc.AddSection() as WSection;
            section.BreakCode = SectionBreakCode.NewPage;
            newPara           = section.AddParagraph() as WParagraph;
            text = newPara.AppendText("Section2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading2);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");
            #endregion

            toc.IncludePageNumbers    = true;
            toc.RightAlignPageNumbers = true;
            toc.UseHyperlinks         = true;
            toc.LowerHeadingLevel     = 1;
            toc.UpperHeadingLevel     = 3;

            toc.UseOutlineLevels = true;

            //Updates the table of contents.
            doc.UpdateTableOfContents();
            string       filename     = "";
            string       contenttype  = "";
            MemoryStream outputStream = new MemoryStream();
            if (pdfButton != null && (bool)pdfButton.IsChecked)
            {
                filename    = "Table Of Contents.pdf";
                contenttype = "application/pdf";
                DocIORenderer renderer = new DocIORenderer();
                PdfDocument   pdfDoc   = renderer.ConvertToPDF(doc);
                pdfDoc.Save(outputStream);
                pdfDoc.Close();
            }
            else
            {
                filename    = "Table Of Contents.docx";
                contenttype = "application/msword";
                doc.Save(outputStream, FormatType.Docx);
            }

            doc.Close();
            if (Device.RuntimePlatform == Device.UWP)
            {
                DependencyService.Get <ISaveWindowsPhone>()
                .Save(filename, contenttype, outputStream);
            }
            else
            {
                DependencyService.Get <ISave>().Save(filename, contenttype, outputStream);
            }
        }
示例#27
0
        /// <summary>
        /// Generate update table of contents functionality of Essential DocIO
        /// </summary>
        /// <returns>Return the created Word document as stream</returns>
        public MemoryStream TableofContent(string documentType, string button, bool UpdateTOC)
        {
            WordDocument doc = new WordDocument();

            doc.EnsureMinimal();

            WParagraph para = doc.LastParagraph;

            para.AppendText("Essential DocIO - Table of Contents");
            para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            para.ApplyStyle(BuiltinStyle.Heading4);

            para = doc.LastSection.AddParagraph() as WParagraph;
            para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            para.ApplyStyle(BuiltinStyle.Heading4);

            if (!UpdateTOC)
            {
                para.AppendText("Select TOC and press F9 to update the Table of Contents").CharacterFormat.HighlightColor = Syncfusion.Drawing.Color.Yellow;
            }

            para = doc.LastSection.AddParagraph() as WParagraph;

            //Insert TOC
            TableOfContent toc = para.AppendTOC(1, 3);

            para.ApplyStyle(BuiltinStyle.Heading4);

            //Apply built-in paragraph formatting
            WSection section = doc.LastSection;

            #region Default Styles
            WParagraph newPara = section.AddParagraph() as WParagraph;
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendBreak(BreakType.PageBreak);
            WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading1);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Section1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading2);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");

            section.AddParagraph();
            section           = doc.AddSection() as WSection;
            section.BreakCode = SectionBreakCode.NewPage;
            newPara           = section.AddParagraph() as WParagraph;
            text = newPara.AppendText("Section2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading2);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");
            #endregion

            toc.IncludePageNumbers    = true;
            toc.RightAlignPageNumbers = true;
            toc.UseHyperlinks         = true;
            toc.LowerHeadingLevel     = 1;
            toc.UpperHeadingLevel     = 3;

            toc.UseOutlineLevels = true;

            //Updates the table of contents.
            if (UpdateTOC)
            {
                doc.UpdateTableOfContents();
            }

            FormatType formatType = FormatType.Docx;
            //Save as .doc format
            if (documentType == "WordDoc")
            {
                formatType = FormatType.Doc;
            }
            //Save as .xml format
            else if (documentType == "WordML")
            {
                formatType = FormatType.WordML;
            }
            //Save the document as a stream and retrun the stream
            using (MemoryStream stream = new MemoryStream())
            {
                //Save the created Word document to MemoryStream
                doc.Save(stream, formatType);
                doc.Close();
                stream.Position = 0;
                return(stream);
            }
        }
示例#28
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a document
            Document doc = new Document();
            //Add a section
            Section section = doc.AddSection();
            //Customize table of contents with switches
            TableOfContent toc  = new TableOfContent(doc, "{\\o \"1-3\" \\n 1-1}");
            Paragraph      para = section.AddParagraph();

            para.Items.Add(toc);
            para.AppendFieldMark(FieldMarkType.FieldSeparator);
            para.AppendText("TOC");
            para.AppendFieldMark(FieldMarkType.FieldEnd);
            doc.TOC = toc;

            Paragraph par = section.AddParagraph();
            TextRange tr  = par.AppendText("Flowers");

            tr.CharacterFormat.FontSize    = 30;
            par.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;

            //Create paragraph and set the head level
            Paragraph para1 = section.AddParagraph();

            para1.AppendText("Ornithogalum");
            //Apply the Heading1 style
            para1.ApplyStyle(BuiltinStyle.Heading1);
            //Add paragraphs
            para1 = section.AddParagraph();
            DocPicture picture = para1.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\Data\Ornithogalum.jpg"));

            picture.TextWrappingStyle = TextWrappingStyle.Square;
            para1.AppendText("Ornithogalum is a genus of perennial plants mostly native to southern Europe and southern Africa belonging to the family Asparagaceae. Some species are native to other areas such as the Caucasus. Growing from a bulb, species have linear basal leaves and a slender stalk, up to 30 cm tall, bearing clusters of typically white star-shaped flowers, often striped with green.");
            para1 = section.AddParagraph();

            Paragraph para2 = section.AddParagraph();

            para2.AppendText("Rosa");
            //Apply the Heading2 style
            para2.ApplyStyle(BuiltinStyle.Heading2);
            para2 = section.AddParagraph();
            DocPicture picture2 = para2.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\Data\Rosa.jpg"));

            picture2.TextWrappingStyle = TextWrappingStyle.Square;
            para2.AppendText("A rose is a woody perennial flowering plant of the genus Rosa, in the family Rosaceae, or the flower it bears. There are over a hundred species and thousands of cultivars. They form a group of plants that can be erect shrubs, climbing or trailing with stems that are often armed with sharp prickles. Flowers vary in size and shape and are usually large and showy, in colours ranging from white through yellows and reds. Most species are native to Asia, with smaller numbers native to Europe, North America, and northwestern Africa. Species, cultivars and hybrids are all widely grown for their beauty and often are fragrant. Roses have acquired cultural significance in many societies. Rose plants range in size from compact, miniature roses, to climbers that can reach seven meters in height. Different species hybridize easily, and this has been used in the development of the wide range of garden roses.");
            section.AddParagraph();

            Paragraph para3 = section.AddParagraph();

            para3.AppendText("Hyacinth");
            //Apply the Heading3 style
            para3.ApplyStyle(BuiltinStyle.Heading3);
            para3 = section.AddParagraph();
            DocPicture picture3 = para3.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\Data\hyacinths.JPG"));

            picture3.TextWrappingStyle = TextWrappingStyle.Tight;
            para3.AppendText("Hyacinthus is a small genus of bulbous, fragrant flowering plants in the family Asparagaceae, subfamily Scilloideae.These are commonly called hyacinths.The genus is native to the eastern Mediterranean (from the south of Turkey through to northern Israel).");
            para3 = section.AddParagraph();
            para3.AppendText("Several species of Brodiea, Scilla, and other plants that were formerly classified in the lily family and have flower clusters borne along the stalk also have common names with the word \"hyacinth\" in them. Hyacinths should also not be confused with the genus Muscari, which are commonly known as grape hyacinths.");

            //Update TOC
            doc.UpdateTableOfContents();
            //Save to file
            doc.SaveToFile("result.docx", FileFormat.Docx);

            //Launch the Word file
            FileViewer("result.docx");
        }
示例#29
0
        internal void Render_ShouldNotWrite_WhenNoTemplateFound(int expected, PagesRenderer sut, TableOfContent toc, FakePageWriter writer)
        {
            sut.Render(toc, writer);

            Check.That(writer.Written).IsEqualTo(expected);
        }
        public void ChangeReferenceToSameObjectTest()
        {
            Key person1Key, person2Key;
            Key license1Key, license2Key;
            Key tableOfContentKey, item1Key, item2Key;

            using (var populateSession = Domain.OpenSession())
                using (var transaction = populateSession.OpenTransaction()) {
                    var person1 = new Person {
                        DriverLicense = new DriverLicense()
                    };
                    var person2 = new Person {
                        DriverLicense = new DriverLicense()
                    };
                    person1Key  = person1.Key;
                    person2Key  = person2.Key;
                    license1Key = person1.DriverLicense.Key;
                    license2Key = person2.DriverLicense.Key;

                    var tableOfContent = new TableOfContent();
                    tableOfContentKey = tableOfContent.Key;

                    var item1 = new TableOfContentItem();
                    item1Key = item1.Key;
                    tableOfContent.Items.Add(item1);

                    var item2 = new TableOfContentItem();
                    item2Key = item2.Key;
                    tableOfContent.Items.Add(item2);

                    transaction.Complete();
                }

            using (var session = Domain.OpenSession(sessionConfiguration)) {
                var person  = session.Query.Single <Person>(person1Key);
                var license = session.Query.Single <DriverLicense>(license1Key);
                Assert.That(session.NonPairedReferencesRegistry.RemovedReferencesCount, Is.EqualTo(0));
                Assert.That(session.NonPairedReferencesRegistry.AddedReferencesCount, Is.EqualTo(0));
                Assert.That(ReferenceFinder.GetReferencesTo(person).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(license).Count(), Is.EqualTo(1));
                person.DriverLicense = license;
                Assert.That(session.NonPairedReferencesRegistry.RemovedReferencesCount, Is.EqualTo(0));
                Assert.That(session.NonPairedReferencesRegistry.AddedReferencesCount, Is.EqualTo(0));
                Assert.That(ReferenceFinder.GetReferencesTo(person).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(license).Count(), Is.EqualTo(1));

                person  = session.Query.Single <Person>(person2Key);
                license = session.Query.Single <DriverLicense>(license2Key);
                Assert.That(session.NonPairedReferencesRegistry.RemovedReferencesCount, Is.EqualTo(0));
                Assert.That(session.NonPairedReferencesRegistry.AddedReferencesCount, Is.EqualTo(0));
                Assert.That(ReferenceFinder.GetReferencesTo(person).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(license).Count(), Is.EqualTo(1));

                license.Person = person;
                Assert.That(session.NonPairedReferencesRegistry.RemovedReferencesCount, Is.EqualTo(0));
                Assert.That(session.NonPairedReferencesRegistry.AddedReferencesCount, Is.EqualTo(0));
                Assert.That(ReferenceFinder.GetReferencesTo(person).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(license).Count(), Is.EqualTo(1));

                var item1          = session.Query.Single <TableOfContentItem>(item1Key);
                var item2          = session.Query.Single <TableOfContentItem>(item2Key);
                var tableOfContent = session.Query.Single <TableOfContent>(tableOfContentKey);
                Assert.That(session.NonPairedReferencesRegistry.RemovedReferencesCount, Is.EqualTo(0));
                Assert.That(session.NonPairedReferencesRegistry.AddedReferencesCount, Is.EqualTo(0));
                Assert.That(ReferenceFinder.GetReferencesTo(item1).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(item2).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(tableOfContent).Count(), Is.EqualTo(2));

                item1.TableOfContent = tableOfContent;
                Assert.That(session.NonPairedReferencesRegistry.RemovedReferencesCount, Is.EqualTo(0));
                Assert.That(session.NonPairedReferencesRegistry.AddedReferencesCount, Is.EqualTo(0));
                Assert.That(ReferenceFinder.GetReferencesTo(item1).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(item2).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(tableOfContent).Count(), Is.EqualTo(2));

                item2.TableOfContent = tableOfContent;
                Assert.That(session.NonPairedReferencesRegistry.RemovedReferencesCount, Is.EqualTo(0));
                Assert.That(session.NonPairedReferencesRegistry.AddedReferencesCount, Is.EqualTo(0));
                Assert.That(ReferenceFinder.GetReferencesTo(item1).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(item2).Count(), Is.EqualTo(1));
                Assert.That(ReferenceFinder.GetReferencesTo(tableOfContent).Count(), Is.EqualTo(2));
            }
        }