当前位置: 首页>>代码示例>>C#>>正文


C# DocumentBuilder.EndBookmark方法代码示例

本文整理汇总了C#中DocumentBuilder.EndBookmark方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentBuilder.EndBookmark方法的具体用法?C# DocumentBuilder.EndBookmark怎么用?C# DocumentBuilder.EndBookmark使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DocumentBuilder的用法示例。


在下文中一共展示了DocumentBuilder.EndBookmark方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public static void Run()
        {
            // ExStart:CreateBookmark
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithBookmarks();

            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.StartBookmark("My Bookmark");
            builder.Writeln("Text inside a bookmark.");

            builder.StartBookmark("Nested Bookmark");
            builder.Writeln("Text inside a NestedBookmark.");
            builder.EndBookmark("Nested Bookmark");

            builder.Writeln("Text after Nested Bookmark.");
            builder.EndBookmark("My Bookmark");


            PdfSaveOptions options = new PdfSaveOptions();
            options.OutlineOptions.BookmarksOutlineLevels.Add("My Bookmark", 1);
            options.OutlineOptions.BookmarksOutlineLevels.Add("Nested Bookmark", 2);

            dataDir = dataDir + "Create.Bookmark_out.pdf";
            doc.Save(dataDir, options);
            // ExEnd:CreateBookmark
            Console.WriteLine("\nBookmark created successfully.\nFile saved at " + dataDir);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:29,代码来源:CreateBookmark.cs

示例2: Main

        static void Main(string[] args)
        {
            // Check for license and apply if exists
            string licenseFile = AppDomain.CurrentDomain.BaseDirectory + "Aspose.Words.lic";
            if (File.Exists(licenseFile))
            {
                // Apply Aspose.Words API License
                Aspose.Words.License license = new Aspose.Words.License();
                // Place license file in Bin/Debug/ Folder
                license.SetLicense("Aspose.Words.lic");
            }

            Document doc = new Document("../../data/document.doc");
            DocumentBuilder builder = new DocumentBuilder(doc);

            // ----- Set Bookmark

            builder.StartBookmark("AsposeBookmark");
            builder.Writeln("Text inside a bookmark.");
            builder.EndBookmark("AsposeBookmark");

            // ----- Get Bookmark
            
            // By index.
            Bookmark bookmark1 = doc.Range.Bookmarks[0];

            // By name.
            Bookmark bookmark2 = doc.Range.Bookmarks["AsposeBookmark"];

            doc.Save("AsposeBookmarks.doc");

        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:32,代码来源:Program.cs

示例3: Main

        static void Main(string[] args)
        {
            string mypath = "";
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.StartBookmark("MyBookmark");
            builder.Writeln("Text inside a bookmark.");
            builder.EndBookmark("MyBookmark");
            doc.Save(mypath + "Adding Bookmark.doc");
 
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:12,代码来源:Program.cs

示例4: Run

        public static void Run()
        {
            // ExStart:BookmarkTable
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithBookmarks();
            
            // Create empty document
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            Table table = builder.StartTable();

            // Insert a cell
            builder.InsertCell();

            // Start bookmark here after calling InsertCell
            builder.StartBookmark("MyBookmark");

            builder.Write("This is row 1 cell 1");

            // Insert a cell
            builder.InsertCell();
            builder.Write("This is row 1 cell 2");

            builder.EndRow();

            // Insert a cell
            builder.InsertCell();
            builder.Writeln("This is row 2 cell 1");

            // Insert a cell
            builder.InsertCell();
            builder.Writeln("This is row 2 cell 2");

            builder.EndRow();

            builder.EndTable();
            // End of bookmark
            builder.EndBookmark("MyBookmark");

            dataDir = dataDir + "Bookmark.Table_out.doc";
            doc.Save(dataDir);
            // ExEnd:BookmarkTable
            Console.WriteLine("\nTable bookmarked successfully.\nFile saved at " + dataDir);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:45,代码来源:BookmarkTable.cs

示例5: Run

        public static void Run()
        {
            // ExStart:DocumentBuilderInsertBookmark
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithDocument();
            // Initialize document.
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.StartBookmark("FineBookmark");
            builder.Writeln("This is just a fine bookmark.");
            builder.EndBookmark("FineBookmark");

            dataDir = dataDir + "DocumentBuilderInsertBookmark_out.doc";
            doc.Save(dataDir);
            // ExEnd:DocumentBuilderInsertBookmark
            Console.WriteLine("\nBookmark using DocumentBuilder inserted successfully.\nFile saved at " + dataDir);
        }     
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:18,代码来源:DocumentBuilderInsertBookmark.cs

示例6: Main

        static void Main(string[] args)
        {
            Document doc = new Document("../../data/document.doc");
            DocumentBuilder builder = new DocumentBuilder(doc);

            // ----- Set Bookmark

            builder.StartBookmark("AsposeBookmark");
            builder.Writeln("Text inside a bookmark.");
            builder.EndBookmark("AsposeBookmark");

            // ----- Get Bookmark

            // By index.
            Bookmark bookmark1 = doc.Range.Bookmarks[0];

            // By name.
            Bookmark bookmark2 = doc.Range.Bookmarks["AsposeBookmark"];

            doc.Save("AsposeBookmarks.doc");
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:21,代码来源:Program.cs

示例7: ConvertNumPageFieldsToPageRef

        /// <summary>
        /// Replaces all NUMPAGES fields in the document with PAGEREF fields. The replacement field displays the total number
        /// of pages in the sub document instead of the total pages in the document.
        /// </summary>
        /// <param name="doc">The combined document to process</param>
        public static void ConvertNumPageFieldsToPageRef(Document doc)
        {
            // This is the prefix for each bookmark which signals where page numbering restarts.
            // The underscore "_" at the start inserts this bookmark as hidden in MS Word.
            const string bookmarkPrefix = "_SubDocumentEnd";
            // Field name of the NUMPAGES field.
            const string numPagesFieldName = "NUMPAGES";
            // Field name of the PAGEREF field.
            const string pageRefFieldName = "PAGEREF";

            // Create a new DocumentBuilder which is used to insert the bookmarks and replacement fields.
            DocumentBuilder builder = new DocumentBuilder(doc);
            // Defines the number of page restarts that have been encountered and therefore the number of "sub" documents
            // found within this document.
            int subDocumentCount = 0;

            // Iterate through all sections in the document.
            foreach (Section section in doc.Sections)
            {
                // This section has it's page numbering restarted so we will treat this as the start of a sub document.
                // Any PAGENUM fields in this inner document must be converted to special PAGEREF fields to correct numbering.
                if (section.PageSetup.RestartPageNumbering)
                {
                    // Don't do anything if this is the first section in the document. This part of the code will insert the bookmark marking
                    // the end of the previous sub document so therefore it is not applicable for first section in the document.
                    if (!section.Equals(doc.FirstSection))
                    {
                        // Get the previous section and the last node within the body of that section.
                        Section prevSection = (Section)section.PreviousSibling;
                        Node lastNode = prevSection.Body.LastChild;

                        // Use the DocumentBuilder to move to this node and insert the bookmark there.
                        // This bookmark represents the end of the sub document.
                        builder.MoveTo(lastNode);
                        builder.StartBookmark(bookmarkPrefix + subDocumentCount);
                        builder.EndBookmark(bookmarkPrefix + subDocumentCount);

                        // Increase the subdocument count to insert the correct bookmarks.
                        subDocumentCount++;
                    }
                }

                // The last section simply needs the ending bookmark to signal that it is the end of the current sub document.
                if (section.Equals(doc.LastSection))
                {
                    // Insert the bookmark at the end of the body of the last section.
                    // Don't increase the count this time as we are just marking the end of the document.
                    Node lastNode = doc.LastSection.Body.LastChild;
                    builder.MoveTo(lastNode);
                    builder.StartBookmark(bookmarkPrefix + subDocumentCount);
                    builder.EndBookmark(bookmarkPrefix + subDocumentCount);
                }

                // Iterate through each NUMPAGES field in the section and replace the field with a PAGEREF field referring to the bookmark of the current subdocument
                // This bookmark is positioned at the end of the sub document but does not exist yet. It is inserted when a section with restart page numbering or the last
                // section is encountered.
                Node[] nodes = section.GetChildNodes(NodeType.FieldStart, true).ToArray();
                foreach (FieldStart fieldStart in nodes)
                {
                    if (fieldStart.FieldType == FieldType.FieldNumPages)
                    {
                        // Get the field code.
                        string fieldCode = GetFieldCode(fieldStart);
                        // Since the NUMPAGES field does not take any additional parameters we can assume the remaining part of the field
                        // code after the fieldname are the switches. We will use these to help recreate the NUMPAGES field as a PAGEREF field.
                        string fieldSwitches = fieldCode.Replace(numPagesFieldName, "").Trim();

                        // Inserting the new field directly at the FieldStart node of the original field will cause the new field to
                        // not pick up the formatting of the original field. To counter this insert the field just before the original field
                        Node previousNode = fieldStart.PreviousSibling;

                        // If a previous run cannot be found then we are forced to use the FieldStart node.
                        if (previousNode == null)
                            previousNode = fieldStart;

                        // Insert a PAGEREF field at the same position as the field.
                        builder.MoveTo(previousNode);
                        // This will insert a new field with a code like " PAGEREF _SubDocumentEnd0 *\MERGEFORMAT ".
                        Field newField = builder.InsertField(string.Format(" {0} {1}{2} {3} ", pageRefFieldName, bookmarkPrefix, subDocumentCount, fieldSwitches));

                        // The field will be inserted before the referenced node. Move the node before the field instead.
                        previousNode.ParentNode.InsertBefore(previousNode, newField.Start);

                        // Remove the original NUMPAGES field from the document.
                        RemoveField(fieldStart);
                    }
                }
            }
        }
开发者ID:nausherwan-aslam,项目名称:Aspose_Words_NET,代码行数:94,代码来源:Program.cs

示例8: InsertBookmarks

        private static void InsertBookmarks(Document doc)
        {
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.StartBookmark("My Bookmark");
            builder.Writeln("Text inside a bookmark.");

            builder.StartBookmark("Nested Bookmark");
            builder.Writeln("Text inside a NestedBookmark.");
            builder.EndBookmark("Nested Bookmark");

            builder.Writeln("Text after Nested Bookmark.");
            builder.EndBookmark("My Bookmark");

            builder.StartBookmark("Bookmark_WithoutWhiteSpaces");
            builder.Writeln("Text inside a NestedBookmark.");
            builder.EndBookmark("Bookmark_WithoutWhiteSpaces");
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:18,代码来源:ExBookmarks.cs

示例9: BookmarksInsertBookmarkWithDocumentBuilder

        public void BookmarksInsertBookmarkWithDocumentBuilder()
        {
            //ExStart
            //ExId:BookmarksInsertBookmark
            //ExSummary:Shows how to create a new bookmark.
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.StartBookmark("MyBookmark");
            builder.Writeln("Text inside a bookmark.");
            builder.EndBookmark("MyBookmark");
            //ExEnd
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:13,代码来源:ExBookmarks.cs

示例10: DocumentBuilderInsertBookmark

        public void DocumentBuilderInsertBookmark()
        {
            //ExStart
            //ExId:DocumentBuilderInsertBookmark
            //ExSummary:Shows how to insert a bookmark into a document using a document builder.
            Aspose.Words.Document doc = new Aspose.Words.Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.StartBookmark("FineBookmark");
            builder.Writeln("This is just a fine bookmark.");
            builder.EndBookmark("FineBookmark");
            //ExEnd
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:13,代码来源:ExDocumentBuilder.cs

示例11: InsertTextAndBookmark

        public void InsertTextAndBookmark()
        {
            //ExStart
            //ExFor:DocumentBuilder
            //ExFor:DocumentBuilder.StartBookmark
            //ExFor:DocumentBuilder.EndBookmark
            //ExSummary:Adds some text into the document and encloses the text in a bookmark using DocumentBuilder.
            DocumentBuilder builder = new DocumentBuilder();

            builder.StartBookmark("MyBookmark");
            builder.Writeln("Text inside a bookmark.");
            builder.EndBookmark("MyBookmark");
            //ExEnd
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:14,代码来源:ExDocumentBuilder.cs

示例12: InsertHyperlinkToLocalBookmark

        public void InsertHyperlinkToLocalBookmark()
        {
            //ExStart
            //ExFor:DocumentBuilder.StartBookmark
            //ExFor:DocumentBuilder.EndBookmark
            //ExFor:DocumentBuilder.InsertHyperlink
            //ExSummary:Inserts a hyperlink referencing local bookmark.
            Aspose.Words.Document doc = new Aspose.Words.Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.StartBookmark("Bookmark1");
            builder.Write("Bookmarked text.");
            builder.EndBookmark("Bookmark1");

            builder.Writeln("Some other text");

            // Specify font formatting for the hyperlink.
            builder.Font.Color = Color.Blue;
            builder.Font.Underline = Underline.Single;

            // Insert hyperlink.
            // Switch \o is used to provide hyperlink tip text.
            builder.InsertHyperlink("Hyperlink Text", @"Bookmark1"" \o ""Hyperlink Tip", true);

            // Clear hyperlink formatting.
            builder.Font.ClearFormatting();

            doc.Save(ExDir + "DocumentBuilder.InsertHyperlinkToLocalBookmark Out.doc");
            //ExEnd
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:30,代码来源:ExDocumentBuilder.cs

示例13: AddsBookmarkEndsToParagraph_WhenStartVisitingFromParagraph

        public void AddsBookmarkEndsToParagraph_WhenStartVisitingFromParagraph()
        {
            const string FirstBookmarkName = "Bookmark 1";
            const string SecondBookmarkName = "Bookmark 2";
            var builder = new DocumentBuilder();
            builder.StartBookmark(FirstBookmarkName);
            builder.EndBookmark(FirstBookmarkName);
            builder.StartBookmark(SecondBookmarkName);
            builder.EndBookmark(SecondBookmarkName);
            Paragraph paragraph = builder.Document.FirstSection.Body.FirstParagraph;

            var paragraphProxy = new ParagraphProxy();
            var firstBookmarkEndProxy = A.Fake<BookmarkEndProxy>();
            var secondBookmarkEndProxy = A.Fake<BookmarkEndProxy>();

            A.CallTo(() => this.proxyFactory.CreateParagraph()).Returns(paragraphProxy);
            A.CallTo(() => this.proxyFactory.CreateBookmarkEnd(FirstBookmarkName)).Returns(firstBookmarkEndProxy);
            A.CallTo(() => this.proxyFactory.CreateBookmarkEnd(SecondBookmarkName)).Returns(secondBookmarkEndProxy);

            paragraph.Accept(this.testee);

            paragraphProxy.Children.Should().ContainInOrder(firstBookmarkEndProxy, secondBookmarkEndProxy);
        }
开发者ID:philippdolder,项目名称:AsposeVisualizer,代码行数:23,代码来源:ProxyDocumentVisitorFacts.cs

示例14: SetsBookmarkStartAsRoot_WhenStartVisitingFromBookmarkStart

        public void SetsBookmarkStartAsRoot_WhenStartVisitingFromBookmarkStart()
        {
            const string BookmarkName = "Bookmark";
            var builder = new DocumentBuilder();
            BookmarkStart bookmarkStart = builder.StartBookmark(BookmarkName);
            builder.EndBookmark(BookmarkName);

            var bookmarkStartProxy = A.Fake<BookmarkStartProxy>();

            A.CallTo(() => this.proxyFactory.CreateBookmarkStart(BookmarkName)).Returns(bookmarkStartProxy);

            bookmarkStart.Accept(this.testee);

            this.testee.Root.Should().Be(bookmarkStartProxy);
        }
开发者ID:philippdolder,项目名称:AsposeVisualizer,代码行数:15,代码来源:ProxyDocumentVisitorFacts.cs

示例15: FromStrings

        public static Document FromStrings(string[] strings, out Run[] runs)
        {
            var builder = new DocumentBuilder();

            var runList = new List<Run>();

            var comments = new Dictionary<string, Comment>();

            foreach (var str in strings)
            {
                // Bookmark
                if (str.StartsWith("@{") && str.EndsWith("}"))
                {
                    if (str.StartsWith("@{/"))
                    {
                        var bookmarkName = str.Substring(3, str.Length - 4);
                        builder.EndBookmark(bookmarkName);
                    }
                    else
                    {
                        var bookmarkName = str.Substring(2, str.Length - 3);
                        builder.StartBookmark(bookmarkName);
                    }

                    continue;
                }

                // Comment
                if (str.StartsWith("!{") && str.EndsWith("}"))
                {
                    if (str.StartsWith("!{/"))
                    {
                        var commentName = str.Substring(3, str.Length - 4);

                        var comment = comments[commentName];

                        var commentEnd = new CommentRangeEnd(builder.Document, comment.Id);

                        builder.InsertNode(commentEnd);
                    }
                    else
                    {
                        var commentName = str.Substring(2, str.Length - 3);

                        var comment = new Comment(builder.Document, "", "", DateTime.Now);

                        comments.Add(commentName, comment);

                        comment.SetText("Comment: " + commentName);

                        builder.InsertNode(comment);

                        var commentStart = new CommentRangeStart(builder.Document, comment.Id);

                        builder.InsertNode(commentStart);
                    }

                    continue;
                }

                runList.Add(builder.InsertRun(str));
            }

            runs = runList.ToArray();

            return builder.Document;
        }
开发者ID:vc3,项目名称:ExoMerge,代码行数:67,代码来源:DocumentConverter.cs


注:本文中的DocumentBuilder.EndBookmark方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。