public static void Run()
        {
            // ExStart:AddChildBookmark
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Bookmarks();
            // Create bookmarks
            Aspose.Pdf.Facades.Bookmarks bookmarks = new Aspose.Pdf.Facades.Bookmarks();
            Bookmark childBookmark1 = new Bookmark();
            childBookmark1.PageNumber = 1;
            childBookmark1.Title = "First Child";
            Bookmark childBookmark2 = new Bookmark();
            childBookmark2.PageNumber = 2;
            childBookmark2.Title = "Second Child";

            bookmarks.Add(childBookmark1);
            bookmarks.Add(childBookmark2);

            Bookmark bookmark = new Bookmark();
            bookmark.Action = "GoTo";
            bookmark.PageNumber = 1;
            bookmark.Title = "Parent";

            bookmark.ChildItems = bookmarks;

            // Create PdfBookmarkEditor class
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
            // Bind PDF document
            bookmarkEditor.BindPdf(dataDir+ "AddChildBookmark.pdf");
            // Create bookmarks
            bookmarkEditor.CreateBookmarks(bookmark);
            // Save updated document
            bookmarkEditor.Save(dataDir+ "AddChildBookmark_out.pdf");
            // ExEnd:AddChildBookmark
        }
        public static void Run()
        {
            // ExStart:GetBookmarkPageNumber
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();

            // Create PdfBookmarkEditor
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();

            // Open PDF file
            bookmarkEditor.BindPdf(dataDir + "GetBookmarks.pdf");
            // Extract bookmarks
            Aspose.Pdf.Facades.Bookmarks bookmarks = bookmarkEditor.ExtractBookmarks();
            foreach (Aspose.Pdf.Facades.Bookmark bookmark in bookmarks)
            {
                string strLevelSeprator = string.Empty;
                for (int i = 1; i < bookmark.Level; i++)
                {
                    strLevelSeprator += "----";
                }

                Console.WriteLine("{0}Title: {1}", strLevelSeprator, bookmark.Title);
                Console.WriteLine("{0}Page Number: {1}", strLevelSeprator, bookmark.PageNumber);
                Console.WriteLine("{0}Page Action: {1}", strLevelSeprator, bookmark.Action);
            }
            // ExEnd:GetBookmarkPageNumber
        }
        public static void Run()
        {
            // ExStart:GetBookmarkPageNumber
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();

            // Create PdfBookmarkEditor
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
            // Open PDF file
            bookmarkEditor.BindPdf(dataDir + "GetBookmarks.pdf");
            // Extract bookmarks
            Aspose.Pdf.Facades.Bookmarks bookmarks = bookmarkEditor.ExtractBookmarks();
            foreach (Aspose.Pdf.Facades.Bookmark bookmark in bookmarks)
            {
                string strLevelSeprator = string.Empty;
                for (int i = 1; i < bookmark.Level; i++)
                {
                    strLevelSeprator += "----";
                }

                Console.WriteLine("{0}Title: {1}", strLevelSeprator, bookmark.Title);
                Console.WriteLine("{0}Page Number: {1}", strLevelSeprator, bookmark.PageNumber);
                Console.WriteLine("{0}Page Action: {1}", strLevelSeprator, bookmark.Action);
            }
            // ExEnd:GetBookmarkPageNumber
        }
Esempio n. 4
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");
            //create bookmarks
            Bookmarks bookmarks = new Bookmarks();
            Bookmark childBookmark1 = new Bookmark();
            childBookmark1.PageNumber = 1;
            childBookmark1.Title = "First Child";
            Bookmark childBookmark2 = new Bookmark();
            childBookmark2.PageNumber = 2;
            childBookmark2.Title = "Second Child";

            bookmarks.Add(childBookmark1);
            bookmarks.Add(childBookmark2);

            Bookmark bookmark = new Bookmark();
            bookmark.Action = "GoTo";
            bookmark.PageNumber = 1;
            bookmark.Title = "Parent";

            bookmark.ChildItems = bookmarks;

            //create PdfBookmarkEditor class
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
            //bind PDF document
            bookmarkEditor.BindPdf(dataDir+ "input.pdf");
            //create bookmarks
            bookmarkEditor.CreateBookmarks(bookmark);
            //save updated document
            bookmarkEditor.Save(dataDir+ "output.pdf");
        }
Esempio n. 5
0
 public static void Main()
 {
     // The path to the documents directory.
     string dataDir = Path.GetFullPath("../../../Data/");
     //open document
     PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
     bookmarkEditor.BindPdf(dataDir+ "input.pdf");
     //create bookmark of all pages
     bookmarkEditor.CreateBookmarks(System.Drawing.Color.Green, true, true);
     //save updated PDF file
     bookmarkEditor.Save(dataDir+ "output.pdf");
 }
Esempio n. 6
0
 public static void Main()
 {
     // The path to the documents directory.
     string dataDir = Path.GetFullPath("../../../Data/");
     //open document
     PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
     bookmarkEditor.BindPdf(dataDir+ "input.pdf");
     //delete bookmark
     bookmarkEditor.DeleteBookmarks("Page2");
     //save updated PDF file
     bookmarkEditor.Save(dataDir+ "output.pdf");
 }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Bookmarks();
            //open document
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();

            bookmarkEditor.BindPdf(dataDir + "CreateBookmark-Page.pdf");
            //create bookmark of a particular page
            bookmarkEditor.CreateBookmarkOfPage("Bookmark Name", 2);
            //save updated PDF file
            bookmarkEditor.Save(dataDir + "CreateBookmark-Page_out.pdf");
        }
Esempio n. 8
0
 public static void Main()
 {
     // The path to the documents directory.
     string dataDir = Path.GetFullPath("../../../Data/");
     //Create PdfBookmarkEditor object
     PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
     //Open PDF file
     bookmarkEditor.BindPdf(dataDir+ "input.pdf");
     //Export bookmarks
     bookmarkEditor.ExportBookmarksToXML(dataDir+ "bookmarks.xml");
     //Save updated PDF
     bookmarkEditor.Save(dataDir+ "output.pdf");
 }
Esempio n. 9
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Bookmarks();
            //open document
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();

            bookmarkEditor.BindPdf(dataDir + "UpdateBookmark.pdf");
            //update bookmark
            bookmarkEditor.ModifyBookmarks("New Bookmark", "New Title");
            //save updated PDF file
            bookmarkEditor.Save(dataDir + "UpdateBookmark_out.pdf");
        }
Esempio n. 10
0
 public static void Run()
 {
     // The path to the documents directory.
     string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Bookmarks();
     //open document
     PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
     bookmarkEditor.BindPdf(dataDir+ "CreateBookmark-Page.pdf");
     //create bookmark of a particular page
     bookmarkEditor.CreateBookmarkOfPage("Bookmark Name", 2);
     //save updated PDF file
     bookmarkEditor.Save(dataDir+ "CreateBookmark-Page_out.pdf");
     
 }
Esempio n. 11
0
 public static void Main()
 {
     // The path to the documents directory.
     string dataDir = Path.GetFullPath("../../../Data/");
     //create PdfBookmarkEditor class
     PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
     //open PDF file
     bookmarkEditor.BindPdf(dataDir+ "input.pdf");
     //import bookmarks
     bookmarkEditor.ImportBookmarksWithXML(dataDir+ "bookmarks.xml");
     //save updated PDF file
     bookmarkEditor.Save(dataDir+ "output.pdf");
 }
 public static void Run()
 {
     // The path to the documents directory.
     string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Bookmarks();
     //open document
     PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
     bookmarkEditor.BindPdf(dataDir+ "CreateBookmarks-PagesProperties.pdf");
     //create bookmark of all pages
     bookmarkEditor.CreateBookmarks(System.Drawing.Color.Green, true, true);
     //save updated PDF file
     bookmarkEditor.Save(dataDir+ "CreateBookmarks-PagesProperties_out.pdf");
     
     
 }
Esempio n. 13
0
 public static void Run()
 {
     // The path to the documents directory.
     string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Bookmarks();
     //open document
     PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
     bookmarkEditor.BindPdf(dataDir+ "DeleteABookmark.pdf");
     //delete bookmark
     bookmarkEditor.DeleteBookmarks("Page2");
     //save updated PDF file
     bookmarkEditor.Save(dataDir+ "DeleteABookmark_out.pdf");
     
     
 }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Bookmarks();
            //create PdfBookmarkEditor class
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();

            //open PDF file
            bookmarkEditor.BindPdf(dataDir + "ImportFromXML.pdf");
            //import bookmarks
            bookmarkEditor.ImportBookmarksWithXML(dataDir + "bookmarks.xml");
            //save updated PDF file
            bookmarkEditor.Save(dataDir + "ImportFromXML_out.pdf");
        }
Esempio n. 15
0
 public static void Run()
 {
     // The path to the documents directory.
     string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Bookmarks();
     //open document
     PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
     bookmarkEditor.BindPdf(dataDir+ "CreateBookmarksAll.pdf");
     //create bookmark of all pages
     bookmarkEditor.CreateBookmarks();
     //save updated PDF file
     bookmarkEditor.Save(dataDir+ "Output.pdf");
     
     
 }
 public static void Run()
 {
     // ExStart:UpdateBookmark
     // The path to the documents directory.
     string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Bookmarks();
     // Open document
     PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
     bookmarkEditor.BindPdf(dataDir+ "UpdateBookmark.pdf");
     // Update bookmark
     bookmarkEditor.ModifyBookmarks("New Bookmark", "New Title");
     // Save updated PDF file
     bookmarkEditor.Save(dataDir+ "UpdateBookmark_out.pdf");
     // ExEnd:UpdateBookmark
 }
 public static void Run()
 {
     // ExStart:ExportToXML
     // The path to the documents directory.
     string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Bookmarks();
     // Create PdfBookmarkEditor object
     PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
     // Open PDF file
     bookmarkEditor.BindPdf(dataDir+ "ExportToXML.pdf");
     // Export bookmarks
     bookmarkEditor.ExportBookmarksToXML(dataDir+ "bookmarks.xml");
     // Save updated PDF
     bookmarkEditor.Save(dataDir+ "ExportToXML_out.pdf");
     // ExEnd:ExportToXML            
 }
 public static void Run()
 {
     // ExStart:DeleteAllBookmarks
     // The path to the documents directory.
     string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Bookmarks();
     // Open document
     PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
     bookmarkEditor.BindPdf(dataDir+ "DeleteAllBookmarks.pdf");
     // Delete bookmark
     bookmarkEditor.DeleteBookmarks();
     // Save updated PDF file
     bookmarkEditor.Save(dataDir+ "DeleteAllBookmarks_out.pdf");
     // ExEnd:DeleteAllBookmarks
     
 }
Esempio n. 19
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Bookmarks();
            //create PdfBookmarkEditor class
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
            //open PDF file
            bookmarkEditor.BindPdf(dataDir+ "ImportFromXML.pdf");
            //import bookmarks
            bookmarkEditor.ImportBookmarksWithXML(dataDir+ "bookmarks.xml");
            //save updated PDF file
            bookmarkEditor.Save(dataDir+ "ImportFromXML_out.pdf");
 
            
            
        }
Esempio n. 20
0
 public static void Main()
 {
     // The path to the documents directory.
     string dataDir = Path.GetFullPath("../../../Data/");
     //create bookmark
     Bookmark boomark = new Bookmark();
     boomark.PageNumber = 1;
     boomark.Title = "New Bookmark";
     //create PdfBookmarkEditor class
     PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
     //bind PDF document
     bookmarkEditor.BindPdf(dataDir+ "input.pdf");
     //create bookmarks
     bookmarkEditor.CreateBookmarks(boomark);
     //save updated document
     bookmarkEditor.Save(dataDir+ "output.pdf");
 }
Esempio n. 21
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");
            //create PdfBookmarkEditor
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
            //open PDF file
            bookmarkEditor.BindPdf(dataDir+ "input.pdf");
            //extract bookmarks
            Bookmarks bookmarks = bookmarkEditor.ExtractBookmarks();

            foreach (Bookmark bookmark in bookmarks)
            {
                Console.WriteLine("Title: {0}", bookmark.Title);
                Console.WriteLine("Page Number: {0}", bookmark.PageNumber);
            }
        }
        public void CreateMissingOutlineLevels()
        {
            //ExStart
            //ExFor:Saving.PdfSaveOptions.OutlineOptions.CreateMissingOutlineLevels
            //ExSummary:Shows how to create missing outline levels saving the document in pdf
            Document doc = new Document();

            DocumentBuilder builder = new DocumentBuilder(doc);

            // Creating TOC entries
            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;

            builder.Writeln("Heading 1");

            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading4;

            builder.Writeln("Heading 1.1.1.1");
            builder.Writeln("Heading 1.1.1.2");

            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading9;

            builder.Writeln("Heading 1.1.1.1.1.1.1.1.1");
            builder.Writeln("Heading 1.1.1.1.1.1.1.1.2");

            //Create "PdfSaveOptions" with some mandatory parameters
            //"HeadingsOutlineLevels" specifies how many levels of headings to include in the document outline
            //"CreateMissingOutlineLevels" determining whether or not to create missing heading levels
            PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();

            pdfSaveOptions.OutlineOptions.HeadingsOutlineLevels = 9;
            pdfSaveOptions.OutlineOptions.CreateMissingOutlineLevels = true;
            pdfSaveOptions.SaveFormat = SaveFormat.Pdf;

            doc.Save(MyDir + @"\Artifacts\CreateMissingOutlineLevels.pdf", pdfSaveOptions);
            //ExEnd

            //Bind pdf with Aspose PDF
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
            bookmarkEditor.BindPdf(MyDir + @"\Artifacts\CreateMissingOutlineLevels.pdf");

            //Get all bookmarks from the document
            Bookmarks bookmarks = bookmarkEditor.ExtractBookmarks();

            Assert.AreEqual(11, bookmarks.Count);
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Bookmarks();
            //create PdfBookmarkEditor
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();

            //open PDF file
            bookmarkEditor.BindPdf(dataDir + "ExtractBookmarks.pdf");
            //extract bookmarks
            Aspose.Pdf.Facades.Bookmarks bookmarks = bookmarkEditor.ExtractBookmarks();

            foreach (Bookmark bookmark in bookmarks)
            {
                Console.WriteLine("Title: {0}", bookmark.Title);
                Console.WriteLine("Page Number: {0}", bookmark.PageNumber);
            }
        }
        public static void Run()
        {
            // ExStart:CreateBookmarkPageRange
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Bookmarks();

            // Open document
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
            bookmarkEditor.BindPdf( dataDir + "CreateBookmark-Page.pdf");
            // Bookmark name list
            string[] bookmarkList = { "First" };
            // Page list
            int[] pageList = { 1 };
            // Create bookmark of a range of pages
            bookmarkEditor.CreateBookmarkOfPage(bookmarkList, pageList);
            // Save updated PDF file
            bookmarkEditor.Save( dataDir + "CreateBookmarkPageRange_out.pdf");          
            // ExEnd:CreateBookmarkPageRange
        }
 public static void Run()
 {
     // ExStart:AddBookmark
     // The path to the documents directory.
     string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Bookmarks();
     // Create bookmark
     Bookmark boomark = new Bookmark();
     boomark.PageNumber = 1;
     boomark.Title = "New Bookmark";
     // Create PdfBookmarkEditor class
     PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
     // Bind PDF document
     bookmarkEditor.BindPdf(dataDir+ "AddBookmark.pdf");
     // Create bookmarks
     bookmarkEditor.CreateBookmarks(boomark);
     // Save updated document
     bookmarkEditor.Save(dataDir+ "AddBookmark_out.pdf");
     // ExEnd:AddBookmark
 }
        public static void Run()
        {
            // ExStart:ExtractBookmarks
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Bookmarks();
            // Create PdfBookmarkEditor
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
            // Open PDF file
            bookmarkEditor.BindPdf(dataDir+ "ExtractBookmarks.pdf");
            // Extract bookmarks
            Aspose.Pdf.Facades.Bookmarks bookmarks = bookmarkEditor.ExtractBookmarks();

            foreach (Bookmark bookmark in bookmarks)
            {
                Console.WriteLine("Title: {0}", bookmark.Title);
                Console.WriteLine("Page Number: {0}", bookmark.PageNumber);
            }
            // ExEnd:ExtractBookmarks
        }
Esempio n. 27
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Bookmarks();
            //create bookmark
            Bookmark boomark = new Bookmark();

            boomark.PageNumber = 1;
            boomark.Title      = "New Bookmark";
            //create PdfBookmarkEditor class
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();

            //bind PDF document
            bookmarkEditor.BindPdf(dataDir + "AddBookmark.pdf");
            //create bookmarks
            bookmarkEditor.CreateBookmarks(boomark);
            //save updated document
            bookmarkEditor.Save(dataDir + "AddBookmark_out.pdf");
        }
Esempio n. 28
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");
            //create bookmark
            Bookmark boomark = new Bookmark();

            boomark.PageNumber = 1;
            boomark.Title      = "New Bookmark";
            //create PdfBookmarkEditor class
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();

            //bind PDF document
            bookmarkEditor.BindPdf(dataDir + "input.pdf");
            //create bookmarks
            bookmarkEditor.CreateBookmarks(boomark);
            //save updated document
            bookmarkEditor.Save(dataDir + "output.pdf");
        }
Esempio n. 29
0
        public ActionResult <Response> CreateFileWithBK([FromBody] Request request)
        {
            try
            {
                if (!System.IO.File.Exists(serverDirectory + request.filename))
                {
                    throw new Exception("Source File does not Exist");
                }

                string result = "File_With_BK.pdf";

                PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
                bookmarkEditor.BindPdf(serverDirectory + request.filename);

                bookmarkEditor.CreateBookmarks();

                if (System.IO.File.Exists(serverDirectory + result))
                {
                    System.IO.File.Delete(serverDirectory + result);
                }

                bookmarkEditor.Save(serverDirectory + result);

                return(new Response()
                {
                    FileContent = string.Empty,
                    FileName = result,
                    Message = "File Created successfully",
                    Success = true
                });
            }
            catch (Exception ex)
            {
                return(new Response()
                {
                    FileContent = string.Empty,
                    FileName = "",
                    Message = "Could not Create file. " + ex.Message,
                    Success = false
                });
            }
        }
Esempio n. 30
0
 public static void Main()
 {
     // The path to the documents directory.
     string dataDir = Path.GetFullPath("../../../Data/");
     //create PdfBookmarkEditor
     PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
     //open PDF file
     bookmarkEditor.BindPdf(dataDir+ "input.PDF");
     //extract bookmarks
     Aspose.Pdf.Facades.Bookmarks bookmarks = bookmarkEditor.ExtractBookmarks();
     foreach (Aspose.Pdf.Facades.Bookmark bookmark in bookmarks)
     {
     // get the title information of bookmark item
     Console.WriteLine("Title: {0}", bookmark.Title);
     // get the destination page for bookmark
     Console.WriteLine("Page Number: {0}", bookmark.PageNumber);
     // get the information related to associated action with bookmark
     Console.WriteLine("Bookmark Action: " + bookmark.Action);
     }
 }
Esempio n. 31
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");
            //create PdfBookmarkEditor
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();

            //open PDF file
            bookmarkEditor.BindPdf(dataDir + "input.PDF");
            //extract bookmarks
            Aspose.Pdf.Facades.Bookmarks bookmarks = bookmarkEditor.ExtractBookmarks();
            foreach (Aspose.Pdf.Facades.Bookmark bookmark in bookmarks)
            {
                // get the title information of bookmark item
                Console.WriteLine("Title: {0}", bookmark.Title);
                // get the destination page for bookmark
                Console.WriteLine("Page Number: {0}", bookmark.PageNumber);
                // get the information related to associated action with bookmark
                Console.WriteLine("Bookmark Action: " + bookmark.Action);
            }
        }
Esempio n. 32
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");
            //create bookmarks
            Bookmarks bookmarks      = new Bookmarks();
            Bookmark  childBookmark1 = new Bookmark();

            childBookmark1.PageNumber = 1;
            childBookmark1.Title      = "First Child";
            Bookmark childBookmark2 = new Bookmark();

            childBookmark2.PageNumber = 2;
            childBookmark2.Title      = "Second Child";

            bookmarks.Add(childBookmark1);
            bookmarks.Add(childBookmark2);

            Bookmark bookmark = new Bookmark();

            bookmark.Action     = "GoTo";
            bookmark.PageNumber = 1;
            bookmark.Title      = "Parent";

            bookmark.ChildItems = bookmarks;

            //create PdfBookmarkEditor class
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();

            //bind PDF document
            bookmarkEditor.BindPdf(dataDir + "input.pdf");
            //create bookmarks
            bookmarkEditor.CreateBookmarks(bookmark);
            //save updated document
            bookmarkEditor.Save(dataDir + "output.pdf");
        }
Esempio n. 33
0
        /// <summary>
        /// Adds a bookmark to the first page of each of the given PDFs in the Tuple's byte array, using the string in that Tuple for the
        /// title of the bookmark.
        /// </summary>
        /// <param name="pdf">PDF byte array</param>
        /// <param name="titleAndPdfs">Tuples of &lt;Bookmark title, PDF byte array&gt;</param>
        /// <returns>PDF byte array</returns>
        private static byte[] addBookmarksToPdf( byte[] pdf, IEnumerable<Tuple<string, byte[]>> titleAndPdfs )
        {
            using( var tmpPdf = new MemoryStream( pdf ) ) {
                var bookmarkEditor = new PdfBookmarkEditor();
                bookmarkEditor.BindPdf( tmpPdf );
                var count = 1;
                foreach( var titleAndPdf in titleAndPdfs ) {
                    bookmarkEditor.CreateBookmarkOfPage( titleAndPdf.Item1, count );
                    count += new PdfFileInfo( new MemoryStream( titleAndPdf.Item2 ) ).NumberOfPages;
                }

                using( var addBookmarksStream = new MemoryStream() ) {
                    bookmarkEditor.Save( addBookmarksStream );
                    return addBookmarksStream.ToArray();
                }
            }
        }
Esempio n. 34
0
        public ActionResult <Response> CreateFileWithNB([FromBody] Request request)
        {
            try
            {
                if (!System.IO.File.Exists(serverDirectory + request.filename))
                {
                    throw new Exception("Source File does not Exist");
                }

                string result = "File_With_NB.pdf";

                PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
                bookmarkEditor.BindPdf(serverDirectory + request.filename);

                // Creating child items of a chapter, in this example, the first child item also include a child item.
                Bookmark bm11 = new Bookmark();
                // Set the action type of BookMark
                bm11.Action = "GoTo";
                // Set the BookMark Destination page
                bm11.PageNumber = 3;
                // Set the BookMark title.
                bm11.Title = "Section - 1.1.1";

                Bookmark bm12 = new Bookmark();
                // Set the action type of BookMark
                bm12.Action = "GoTo";
                // Set the BookMark Destination page
                bm12.PageNumber = 3;
                // Set the BookMark title.
                bm12.Title = "Section - 2.1.1";


                Bookmark bm1 = new Bookmark();
                bm1.Action     = "GoTo";
                bm1.PageNumber = 2;
                bm1.Title      = "Section - 1.1";

                Bookmark bm2 = new Bookmark();
                bm2.Action     = "GoTo";
                bm2.PageNumber = 2;
                bm2.Title      = "Section - 2.1";

                Aspose.Pdf.Facades.Bookmarks bms1 = new Aspose.Pdf.Facades.Bookmarks();
                bms1.Add(bm11);
                bm1.ChildItems = bms1;

                Aspose.Pdf.Facades.Bookmarks bms2 = new Aspose.Pdf.Facades.Bookmarks();
                bms2.Add(bm12);
                bm2.ChildItems = bms2;

                Aspose.Pdf.Facades.Bookmarks bms0 = new Aspose.Pdf.Facades.Bookmarks();
                bms0.Add(bm1);

                Aspose.Pdf.Facades.Bookmarks bms01 = new Aspose.Pdf.Facades.Bookmarks();
                bms01.Add(bm2);

                // Creating a chapter (Parent Level Bookmark)
                Bookmark bm = new Bookmark();
                bm.Action     = "GoTo";
                bm.PageNumber = 1;
                bm.Title      = "Chapter - 1";
                bm.ChildItems = bms0;
                bookmarkEditor.CreateBookmarks(bm);

                bm            = new Bookmark();
                bm.Action     = "GoTo";
                bm.PageNumber = 1;
                bm.Title      = "Chapter - 2";
                bm.ChildItems = bms01;
                bookmarkEditor.CreateBookmarks(bm);

                if (System.IO.File.Exists(serverDirectory + result))
                {
                    System.IO.File.Delete(serverDirectory + result);
                }

                bookmarkEditor.Save(serverDirectory + result);

                return(new Response()
                {
                    FileContent = string.Empty,
                    FileName = result,
                    Message = "File Created successfully",
                    Success = true
                });
            }
            catch (Exception ex)
            {
                return(new Response()
                {
                    FileContent = string.Empty,
                    FileName = "",
                    Message = "Could not Create file. " + ex.Message,
                    Success = false
                });
            }
        }
        public void AddBookmarkWithWhiteSpaces(SaveFormat saveFormat)
        {
            Document doc = new Document();

            InsertBookmarks(doc);

            if (saveFormat == SaveFormat.Pdf)
            {
                //Save document with pdf save options
                doc.Save(MyDir + @"\Artifacts\Bookmark_WhiteSpaces.pdf", AddBookmarkSaveOptions(SaveFormat.Pdf));

                //Bind pdf with Aspose PDF
                PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
                bookmarkEditor.BindPdf(MyDir + @"\Artifacts\Bookmark_WhiteSpaces.pdf");

                //Get all bookmarks from the document
                Bookmarks bookmarks = bookmarkEditor.ExtractBookmarks();

                Assert.AreEqual(3, bookmarks.Count);

                //Assert that all the bookmarks title are with witespaces
                Assert.AreEqual("My Bookmark", bookmarks[0].Title);
                Assert.AreEqual("Nested Bookmark", bookmarks[1].Title);

                //Assert that the bookmark title without witespaces
                Assert.AreEqual("Bookmark_WithoutWhiteSpaces", bookmarks[2].Title);
            }
            else
            {
                MemoryStream dstStream = new MemoryStream();
                doc.Save(dstStream, AddBookmarkSaveOptions(saveFormat));

                //Get bookmarks from the document
                BookmarkCollection bookmarks = doc.Range.Bookmarks;

                Assert.AreEqual(3, bookmarks.Count);

                //Assert that all the bookmarks title are with witespaces
                Assert.AreEqual("My Bookmark", bookmarks[0].Name);
                Assert.AreEqual("Nested Bookmark", bookmarks[1].Name);

                //Assert that the bookmark title without witespaces
                Assert.AreEqual("Bookmark_WithoutWhiteSpaces", bookmarks[2].Name);
            }
        }