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

            // Open document
            Document pdfDocument = new Document(dataDir + "AddBookmark.pdf");

            // Create a bookmark object
            OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);
            pdfOutline.Title = "Test Outline";
            pdfOutline.Italic = true;
            pdfOutline.Bold = true;
            // Set the destination page number
            pdfOutline.Action = new GoToAction(pdfDocument.Pages[1]);
            // Add bookmark in the document's outline collection.
            pdfDocument.Outlines.Add(pdfOutline);

            dataDir = dataDir + "AddBookmark_out.pdf";
            // Save output
            pdfDocument.Save(dataDir);
            // ExEnd:AddBookmark
            Console.WriteLine("\nBookmark added successfully.\nFile saved at " + dataDir);
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();

            //open document
            Document pdfDocument = new Document(dataDir + "AddChildBookmark.pdf");

            //create a parent bookmark object
            OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);
            pdfOutline.Title = "Parent Outline";
            pdfOutline.Italic = true;
            pdfOutline.Bold = true;

            //set the destination page number
            pdfOutline.Destination = new GoToAction(2);

            //create a child bookmark object
            OutlineItemCollection pdfChildOutline = new OutlineItemCollection(pdfDocument.Outlines);
            pdfChildOutline.Title = "Child Outline";
            pdfChildOutline.Italic = true;
            pdfChildOutline.Bold = true;

            //set the destination page number for child outline
            pdfChildOutline.Destination = new GoToAction(1);

            //add child bookmark in parent bookmark's collection
            pdfOutline.Add(pdfChildOutline);

            //add parent bookmark in the document's outline collection.
            pdfDocument.Outlines.Add(pdfOutline);

            //save output
            pdfDocument.Save(dataDir + "AddChildBookmark_out.pdf");
        }
        public static void Run()
        {
            // ExStart:InheritZoom
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();

            // Open document
            Document doc = new Document(dataDir + "input.pdf");

            // Get outlines/bookmarks collection of PDF file
            OutlineItemCollection item = new OutlineItemCollection(doc.Outlines);
            // Set zoom level as 0
            XYZExplicitDestination dest = new XYZExplicitDestination(2, 100, 100, 0);
            // Add XYZExplicitDestination as action to outlines collection of PDF
            item.Action = new GoToAction(dest);
            // Add item to outlines collection of PDF file
            doc.Outlines.Add(item);

            dataDir = dataDir + "InheritZoom_out.pdf";
            // Save output
            doc.Save(dataDir);
            // ExEnd:InheritZoom
            Console.WriteLine("\nBookmarks updated successfully.\nFile saved at " + dataDir);

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

            // Open document
            Document pdfDocument = new Document(dataDir + "AddChildBookmark.pdf");

            // Create a parent bookmark object
            OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);

            pdfOutline.Title  = "Parent Outline";
            pdfOutline.Italic = true;
            pdfOutline.Bold   = true;

            // Create a child bookmark object
            OutlineItemCollection pdfChildOutline = new OutlineItemCollection(pdfDocument.Outlines);

            pdfChildOutline.Title  = "Child Outline";
            pdfChildOutline.Italic = true;
            pdfChildOutline.Bold   = true;

            // Add child bookmark in parent bookmark's collection
            pdfOutline.Add(pdfChildOutline);
            // Add parent bookmark in the document's outline collection.
            pdfDocument.Outlines.Add(pdfOutline);

            dataDir = dataDir + "AddChildBookmark_out_.pdf";
            // Save output
            pdfDocument.Save(dataDir);
            // ExEnd:AddChildBookmark
            Console.WriteLine("\nChild bookmark added successfully.\nFile saved at " + dataDir);
        }
        public static void Run()
        {
            // ExStart:AddChildBookmark
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();

            // Open document
            Document pdfDocument = new Document(dataDir + "AddChildBookmark.pdf");

            // Create a parent bookmark object
            OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);
            pdfOutline.Title = "Parent Outline";
            pdfOutline.Italic = true;
            pdfOutline.Bold = true;      
          
            // Create a child bookmark object
            OutlineItemCollection pdfChildOutline = new OutlineItemCollection(pdfDocument.Outlines);
            pdfChildOutline.Title = "Child Outline";
            pdfChildOutline.Italic = true;
            pdfChildOutline.Bold = true;
     
            // Add child bookmark in parent bookmark's collection
            pdfOutline.Add(pdfChildOutline);
            // Add parent bookmark in the document's outline collection.
            pdfDocument.Outlines.Add(pdfOutline);
            
            dataDir = dataDir + "AddChildBookmark_out.pdf";
            // Save output
            pdfDocument.Save(dataDir);
            // ExEnd:AddChildBookmark
            Console.WriteLine("\nChild bookmark added successfully.\nFile saved at " + dataDir);

        }
Example #6
0
        public override void Execute(object parameter)
        {
            var outlineItemFromClipboard = OutlineItem.LoadFromClipboard();

            if (outlineItemFromClipboard == null)
            {
                throw new CommandFailedException();
            }

            if (ViewModel.SelectedItem == null)
            {
                throw new CommandFailedException();
            }

            _oldItem = ViewModel.SelectedItem;

            var parentOfSelectedItem = ViewModel.SelectedItem.ParentItem;

            if (parentOfSelectedItem == null)
            {
                _oldItemParentCollection = ViewModel.Document.Items;
            }
            else
            {
                _oldItemParentCollection = parentOfSelectedItem.Items;
            }

            _oldItemIndex = _oldItemParentCollection.IndexOf(_oldItem);
            _oldItemParentCollection.RemoveAt(_oldItemIndex);
            _oldItemParentCollection.Insert(_oldItemIndex, outlineItemFromClipboard);

            outlineItemFromClipboard.IsSelectedInView = true;
        }
Example #7
0
        public static void Run()
        {
            // ExStart:InheritZoom
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();

            // Open document
            Document doc = new Document(dataDir + "input.pdf");

            // get outlines/bookmarks collection of PDF file
            OutlineItemCollection item = new OutlineItemCollection(doc.Outlines);
            // set zoom level as 0
            XYZExplicitDestination dest = new XYZExplicitDestination(2, 100, 100, 0);

            // Add XYZExplicitDestination as action to outlines collection of PDF
            item.Action = new GoToAction(dest);
            // Add item to outlines collection of PDF file
            doc.Outlines.Add(item);

            dataDir = dataDir + "InheritZoom_out_.pdf";
            // Save output
            doc.Save(dataDir);
            // ExEnd:InheritZoom
            Console.WriteLine("\nBookmarks updated successfully.\nFile saved at " + dataDir);
        }
Example #8
0
        public OutlineItem()
        {
            Items = new OutlineItemCollection();

            Items.CollectionChanged += Items_CollectionChanged;
            IsExpandedInView         = true;
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //open document
            Document pdfDocument = new Document(dataDir + "input.pdf");

            //create a parent bookmark object
            OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);
            pdfOutline.Title = "Parent Outline";
            pdfOutline.Italic = true;
            pdfOutline.Bold = true;

            //set the destination page number
            pdfOutline.Destination = new GoToAction(2);

            //create a child bookmark object
            OutlineItemCollection pdfChildOutline = new OutlineItemCollection(pdfDocument.Outlines);
            pdfChildOutline.Title = "Child Outline";
            pdfChildOutline.Italic = true;
            pdfChildOutline.Bold = true;

            //set the destination page number for child outline
            pdfChildOutline.Destination = new GoToAction(1);

            //add child bookmark in parent bookmark's collection
            pdfOutline.Add(pdfChildOutline);

            //add parent bookmark in the document's outline collection.
            pdfDocument.Outlines.Add(pdfOutline);

            //save output
            pdfDocument.Save(dataDir + "output.pdf");
        }
        public static void Run()
        {
            // ExStart:AddBookmark
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();

            // Open document
            Document pdfDocument = new Document(dataDir + "AddBookmark.pdf");

            // Create a bookmark object
            OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);

            pdfOutline.Title  = "Test Outline";
            pdfOutline.Italic = true;
            pdfOutline.Bold   = true;
            // Set the destination page number
            pdfOutline.Action = new GoToAction(pdfDocument.Pages[1]);
            // Add bookmark in the document's outline collection.
            pdfDocument.Outlines.Add(pdfOutline);

            dataDir = dataDir + "AddBookmark_out.pdf";
            // Save output
            pdfDocument.Save(dataDir);
            // ExEnd:AddBookmark
            Console.WriteLine("\nBookmark added successfully.\nFile saved at " + dataDir);
        }
Example #11
0
        public OutlineDocument(string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            FileName = fileName;

            _items = new OutlineItemCollection();
            _items.Add(new OutlineItem("Outline"));

            State = OutlineDocumentState.NewDocument;
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //open document
            Document pdfDocument = new Document(dataDir + "input.pdf");

            //get a bookmark object
            OutlineItemCollection pdfOutline = pdfDocument.Outlines[1];

            pdfOutline.Title  = "Updated Outline";
            pdfOutline.Italic = true;
            pdfOutline.Bold   = true;

            //save output
            pdfDocument.Save(dataDir + "output.pdf");
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();

            //open document
            Document pdfDocument = new Document(dataDir + "UpdateBookmarks.pdf");

            //get a bookmark object
            OutlineItemCollection pdfOutline = pdfDocument.Outlines[1];

            pdfOutline.Title  = "Updated Outline";
            pdfOutline.Italic = true;
            pdfOutline.Bold   = true;

            //save output
            pdfDocument.Save(dataDir + "UpdateBookmarks_out.pdf");
        }
Example #14
0
        public static void Run()
        {
            // ExStart:UpdateBookmarks
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();

            // Open document
            Document pdfDocument = new Document(dataDir + "UpdateBookmarks.pdf");

            // Get a bookmark object
            OutlineItemCollection pdfOutline = pdfDocument.Outlines[1];

            pdfOutline.Title  = "Updated Outline";
            pdfOutline.Italic = true;
            pdfOutline.Bold   = true;

            dataDir = dataDir + "UpdateBookmarks_out.pdf";
            // Save output
            pdfDocument.Save(dataDir);
            // ExEnd:UpdateBookmarks
            Console.WriteLine("\nBookmarks updated successfully.\nFile saved at " + dataDir);
        }
Example #15
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();

            //open document
            Document pdfDocument = new Document(dataDir + "AddBookmark.pdf");

            //create a bookmark object
            OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);
            pdfOutline.Title = "Test Outline";
            pdfOutline.Italic = true;
            pdfOutline.Bold = true;

            //set the destination page number
            pdfOutline.Action = new Aspose.Pdf.InteractiveFeatures.GoToAction(pdfDocument.Pages[1]);

            //add bookmark in the document's outline collection.
            pdfDocument.Outlines.Add(pdfOutline);

            //save output
            pdfDocument.Save(dataDir + "AddBookmark_out.pdf");
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //open document
            Document pdfDocument = new Document(dataDir + "input.pdf");

            //create a bookmark object
            OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);
            pdfOutline.Title = "Test Outline";
            pdfOutline.Italic = true;
            pdfOutline.Bold = true;

            //set the destination page number
            pdfOutline.Action = new Aspose.Pdf.InteractiveFeatures.GoToAction(pdfDocument.Pages[1]);

            //add bookmark in the document's outline collection.
            pdfDocument.Outlines.Add(pdfOutline);

            //save output
            pdfDocument.Save(dataDir + "output.pdf");
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();

            //open document
            Document pdfDocument = new Document(dataDir + "AddChildBookmark.pdf");

            //create a parent bookmark object
            OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);

            pdfOutline.Title  = "Parent Outline";
            pdfOutline.Italic = true;
            pdfOutline.Bold   = true;

            //set the destination page number
            pdfOutline.Destination = new GoToAction(pdfDocument.Pages[2]);

            //create a child bookmark object
            OutlineItemCollection pdfChildOutline = new OutlineItemCollection(pdfDocument.Outlines);

            pdfChildOutline.Title  = "Child Outline";
            pdfChildOutline.Italic = true;
            pdfChildOutline.Bold   = true;

            //set the destination page number for child outline
            pdfChildOutline.Destination = new GoToAction(pdfDocument.Pages[1]);

            //add child bookmark in parent bookmark's collection
            pdfOutline.Add(pdfChildOutline);

            //add parent bookmark in the document's outline collection.
            pdfDocument.Outlines.Add(pdfOutline);

            //save output
            pdfDocument.Save(dataDir + "AddChildBookmark_out.pdf");
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //open document
            Document pdfDocument = new Document(dataDir + "input.pdf");

            //create a parent bookmark object
            OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);

            pdfOutline.Title  = "Parent Outline";
            pdfOutline.Italic = true;
            pdfOutline.Bold   = true;

            //set the destination page number
            pdfOutline.Destination = new GoToAction(2);

            //create a child bookmark object
            OutlineItemCollection pdfChildOutline = new OutlineItemCollection(pdfDocument.Outlines);

            pdfChildOutline.Title  = "Child Outline";
            pdfChildOutline.Italic = true;
            pdfChildOutline.Bold   = true;

            //set the destination page number for child outline
            pdfChildOutline.Destination = new GoToAction(1);

            //add child bookmark in parent bookmark's collection
            pdfOutline.Add(pdfChildOutline);

            //add parent bookmark in the document's outline collection.
            pdfDocument.Outlines.Add(pdfOutline);

            //save output
            pdfDocument.Save(dataDir + "output.pdf");
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //open document
            Document pdfDocument = new Document(dataDir + "input.pdf");

            //create a bookmark object
            OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);

            pdfOutline.Title  = "Test Outline";
            pdfOutline.Italic = true;
            pdfOutline.Bold   = true;

            //set the destination page number
            pdfOutline.Action = new Aspose.Pdf.InteractiveFeatures.GoToAction(pdfDocument.Pages[1]);

            //add bookmark in the document's outline collection.
            pdfDocument.Outlines.Add(pdfOutline);

            //save output
            pdfDocument.Save(dataDir + "output.pdf");
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();

            //open document
            Document pdfDocument = new Document(dataDir + "AddBookmark.pdf");

            //create a bookmark object
            OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);

            pdfOutline.Title  = "Test Outline";
            pdfOutline.Italic = true;
            pdfOutline.Bold   = true;

            //set the destination page number
            pdfOutline.Action = new Aspose.Pdf.InteractiveFeatures.GoToAction(pdfDocument.Pages[1]);

            //add bookmark in the document's outline collection.
            pdfDocument.Outlines.Add(pdfOutline);

            //save output
            pdfDocument.Save(dataDir + "AddBookmark_out.pdf");
        }
        /// <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);
        }
        public static void makeBookmarksInPdf(string[] documentKeySet, string pdfAsString, string fileName)
        {
            // Using Aspose 3rd party library for bookmark creation
            Aspose.Pdf.Document document = new Aspose.Pdf.Document(Program.filePath + fileName);
            // Initializing list of parent bookmark tabs
            OutlineItemCollection[] parent = new OutlineItemCollection[documentKeySet.Length];

            // Iteration to build sub-sections to partent bookmarks
            for (int k = 1; k < documentKeySet.Length; k++)
            {
                // getting total occurences of a key in the PDF
                int keyCount = countOccurences.countNoOfOccurencesOfKey(pdfAsString, documentKeySet[k], fileName);
                // creating individual parent tabs
                parent[k] = new OutlineItemCollection(document.Outlines);
                // Making Parents apprear in bold
                parent[k].Bold = true;

                // Setting names of parent bookmark tabs
                parent[k].Title = documentKeySet[k];

                try
                {
                    // count variable for iteration and naming
                    int count = 0;
                    // checking for pagewise bookmark entry
                    foreach (bookMarkNode item in Program.pageNo)
                    {
                        // chekcing if the key in the page is equal to the current key, then do further operations to add bookmarks
                        if (item.key == documentKeySet[k])
                        {
                            // Creating subsection bookmarks
                            OutlineItemCollection child = new OutlineItemCollection(document.Outlines);
                            // Naming Child Bookmarks
                            child.Title = documentKeySet[k] + "_" + (count + 1);
                            // creating the link of the child bookmark to its respective page
                            child.Destination = new GoToAction(item.page_no);
                            // Inrementing counter variable
                            count = count + 1;
                            // Showing child in Italics
                            child.Italic = true;

                            // Connecting Child to parent bookmarks
                            parent[k].Add(child);
                        }
                    }
                    // adding parent bookmarks to the complete PDF document
                    document.Outlines.Add(parent[k]);
                }
                // Catching exceptions and noting in Output window
                catch (DocumentException dex)
                {
                    Debug.Write(dex.Message);
                }
                catch (IOException ioex)
                {
                    Debug.Write(ioex.Message);
                }
                //Console.WriteLine("" + keyCount);
            }
            // Save the processed PDF File
            document.Save(Program.filePath + fileName.Replace(".pdf", "") + "_processed.pdf");
        }
Example #23
0
        public void SetItemCollection(OutlineItemCollection item)
        {
            var dataObject = new DataObject(Format.Name, item);

            Clipboard.SetDataObject(dataObject, true);
        }