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
        }
예제 #2
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");
        }
예제 #3
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");
 }
예제 #4
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");
        }
        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");
        }
예제 #7
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");
        }
예제 #8
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();
            //save updated PDF file
            bookmarkEditor.Save(dataDir + "Output.pdf");
        }
예제 #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 + "DeleteAllBookmarks.pdf");
            //delete bookmark
            bookmarkEditor.DeleteBookmarks();
            //save updated PDF file
            bookmarkEditor.Save(dataDir + "DeleteAllBookmarks_out.pdf");
        }
예제 #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");
     
 }
예제 #11
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");
            //update bookmark
            bookmarkEditor.ModifyBookmarks("New Bookmark", "New Title");
            //save updated PDF file
            bookmarkEditor.Save(dataDir + "output.pdf");
        }
예제 #12
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");
 }
예제 #13
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");
        }
예제 #15
0
        public static void Run()
        {
            // 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");
        }
예제 #16
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");
     
     
 }
예제 #17
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");
        }
예제 #18
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");
        }
 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
 }
예제 #20
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");
     
     
 }
예제 #22
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");
     
     
 }
예제 #23
0
        public static void Run()
        {
            // ExStart:DeleteABookmark
            // 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");
            // ExEnd:DeleteABookmark
        }
예제 #24
0
 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
     
 }
예제 #26
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");
 
            
            
        }
예제 #27
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");
 }
예제 #28
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());
                }
            }
        }
예제 #29
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");
        }
예제 #30
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");
        }
        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
        }
예제 #32
0
 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
 }
예제 #33
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
                });
            }
        }
        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
        }
예제 #35
0
        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
        }
예제 #36
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");
        }
예제 #37
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();
                }
            }
        }
        /// <summary>
        /// Responsible to merge different pdf documents and generate into one single PDF
        /// along with the bookmark and table of content
        /// </summary>
        /// <returns> Path of the PDF document </returns>
        public string GeneratePDF()
        {
            // Used to keep a track of current generated PDF page number
            int pdfPageNo = 2;

            // Used to create bookmark and Table of content
            List <TOC> toc = new List <TOC>();

            if (!Directory.Exists(PDFFolderPath))
            {
                Directory.CreateDirectory(PDFFolderPath);
            }

            //aspose words license
            //var AsposeLicenseFilePath = "C://Users//Aditya//.nuget//packages//aspose.pdf//19.9.0//lib//net4.0 - client//Aspose.Pdf.lic";
            //if (System.IO.File.Exists(AsposeLicenseFilePath))
            //{
            //    Aspose.Pdf.License WordsLic = new Aspose.Pdf.License();
            //    WordsLic.SetLicense(AsposeLicenseFilePath);
            //}

            if (File.Exists(PDFFilePath))
            {
                File.Delete(PDFFilePath);
            }

            // Used to maintaint the list of all the documents to be merged.
            List <String> inputDocs = new List <String>();

            // Fetches all the documents from the specified DocumentFolderPath
            foreach (string file in Directory.EnumerateFiles(DocumentFolderPath, "*.pdf"))
            {
                inputDocs.Add(file);
            }

            Document targetDoc = new Document();
            Document doc;

            for (int i = 0; i < inputDocs.Count; i++)
            {
                doc = new Document(inputDocs[i]);

                toc.Add(new TOC
                {
                    BookmarkName = Path.GetFileName(doc.FileName),
                    PageNo       = pdfPageNo
                });

                // Add the pages of the source documents to the target document
                targetDoc.Pages.Add(doc.Pages);

                #region Code to generate Blank page between two documents
                Page         pageI = targetDoc.Pages.Insert(pdfPageNo);
                TextFragment textI = new TextFragment("Blank Page");
                pageI.Paragraphs.Add(textI);

                // Create a bookmark object
                OutlineItemCollection pdfOutlineI = new OutlineItemCollection(targetDoc.Outlines);
                pdfOutlineI.Title  = "Blank Page";
                pdfOutlineI.Italic = true;
                pdfOutlineI.Bold   = true;

                // Add bookmark in the document's outline collection.
                targetDoc.Outlines.Add(pdfOutlineI);
                pdfPageNo = pdfPageNo + doc.Pages.Count;
                pdfPageNo++;
                #endregion
            }


            #region Code to generate Table of Content
            string       html    = "";// above html
            HtmlDocument htmlDoc = new HtmlDocument();
            htmlDoc.LoadHtml(html);

            Page tocPage = targetDoc.Pages.Insert(1);
            tocPage.Background = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.White);

            // Create object to represent TOC information
            TocInfo      tocInfo = new TocInfo();
            TextFragment title   = new TextFragment("Table Of Contents");
            title.TextState.FontSize  = 20;
            title.TextState.FontStyle = FontStyles.Bold;

            // Set the title for TOC
            tocInfo.Title   = title;
            tocPage.TocInfo = tocInfo;


            foreach (var item in toc)
            {
                // Create Heading object
                Heading heading2 = new Heading(1);

                TextSegment segment2 = new TextSegment();
                segment2         = new TextSegment();
                heading2.TocPage = tocPage;
                heading2.Segments.Add(segment2);

                // Specify the destination page for heading object
                heading2.DestinationPage = targetDoc.Pages[item.PageNo];

                // Destination page
                heading2.Top = targetDoc.Pages[item.PageNo].Rect.Height;

                // Destination coordinate
                segment2.Text = item.BookmarkName;

                // Add heading to page containing TOC
                tocPage.Paragraphs.Add(heading2);
            }
            #endregion

            targetDoc.Save(PDFFilePath);

            #region Code to bookmark the pages
            // For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-.NET

            // Open document
            PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
            bookmarkEditor.BindPdf(PDFFilePath);

            // Create bookmark of a range of pages
            foreach (var item in toc)
            {
                bookmarkEditor.CreateBookmarkOfPage(item.BookmarkName, item.PageNo);
            }

            // Save updated PDF file
            bookmarkEditor.Save(PDFFilePath);
            #endregion

            return(PDFFilePath);
        }
예제 #39
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
                });
            }
        }