Beispiel #1
0
        public static bool Contains(this PdfBookmark bookmark, PdfDocument document, int pageIdx)
        {
            PdfDestination destination = bookmark.Action?.GetDestination() ?? bookmark.Destination;

            if (destination == null)
            {
                return(false);
            }

            int            firstPage       = destination.PageIndex;
            PdfDestination nextDestination = null;

            while (nextDestination == null)
            {
                var nextBookmark = bookmark.GetNextBookmark(document);

                if (nextBookmark == null)
                {
                    return(pageIdx >= firstPage);
                }

                nextDestination = nextBookmark.Action?.GetDestination() ?? nextBookmark.Destination;
                bookmark        = nextBookmark;
            }

            int lastPage = nextDestination.PageIndex - 1 > firstPage
        ? nextDestination.PageIndex - 1
        : firstPage;

            return(pageIdx >= firstPage && pageIdx <= lastPage);
        }
        public static SelectInfo?GetSelection(this PdfBookmark bookmark,
                                              PdfDocument document)
        {
            PdfDestination destination = bookmark.Action?.Destination ?? bookmark.Destination;

            if (destination == null)
            {
                return(null);
            }

            int firstPage = destination.PageIndex;
            int lastPage  = document.Pages.Count - 1;

            PdfBookmark nextBookmark = bookmark.GetNextBookmark(document);

            if (nextBookmark != null)
            {
                PdfDestination nextDestination = nextBookmark.Action?.Destination ?? nextBookmark.Destination;

                lastPage = nextDestination.PageIndex - 1 > firstPage
          ? nextDestination.PageIndex - 1
          : firstPage;
            }

            return(new SelectInfo
            {
                StartPage = firstPage,
                EndPage = lastPage,
                StartIndex = 0,
                EndIndex = document.Pages[lastPage].Text.CountChars,
            });
        }
Beispiel #3
0
        private TreeViewNode AddChildBookmarks(PdfBookmark bookmark)
        {
            //Root nodes of treeviews are the top part which can have content udnerneath. Here we create a root node
            TreeViewNode rootNode = new TreeViewNode()
            {
                Content = bookmark.Title
            };

            if (bookmark != null)
            {
                //  Checks for child bookmarks
                if (bookmark.Count != 0)
                {
                    //  Runs through child bookmarks
                    for (int i = 0; i < bookmark.Count; i++)
                    {
                        TreeViewNode childNode = new TreeViewNode()
                        {
                            Content = bookmark[i].Title
                        };
                        //  Adds child to rootnode
                        rootNode.Children.Add(childNode);
                    }
                }

                return(rootNode);
            }
            else
            {
                //Return null if no bookmarks
                return(rootNode);
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            //Create an object of PdfDocument class and add page to the document
            PdfDocument pdf  = new PdfDocument();
            PdfPageBase page = pdf.Pages.Add();

            //Add bookmark to the appointed location in the page
            PdfBookmark bookmark = pdf.Bookmarks.Add("Introduction:");

            bookmark.Destination          = new PdfDestination(page);
            bookmark.Destination.Location = new PointF(0, 0);

            //Set the bookmark font style and color
            bookmark.DisplayStyle = PdfTextStyle.Bold;
            bookmark.Color        = Color.SeaGreen;

            //Add childbookmark to the appointed location in the page
            PdfBookmark childBookmark = bookmark.Insert(0, "PREFACE");

            childBookmark.Destination          = new PdfDestination(page);
            childBookmark.Destination.Location = new PointF(400, 300);

            //Set the childbookmark font style and color
            childBookmark.DisplayStyle = PdfTextStyle.Regular;
            childBookmark.Color        = Color.Black;

            //Save to file and open the document
            pdf.SaveToFile("Bookmark.pdf");
            System.Diagnostics.Process.Start("Bookmark.pdf");
        }
Beispiel #5
0
 private void BackToParentButton_Clicked(object sender, EventArgs e)
 {
     try
     {
         if (listViewItemsSource != null && listViewItemsSource.Count > 0)
         {
             for (int i = listViewItemsSource.Count - 1; i >= 0; i--)
             {
                 listViewItemsSource.RemoveAt(i);
             }
         }
     }
     catch (Exception)
     {
     }
     if (navigationQueue.Count < 2)
     {
         for (int i = 0; i < bookmarkLoadedDocument.Bookmarks.Count; i++)
         {
             listViewItemsSource.Add(new CustomBookmark(bookmarkLoadedDocument.Bookmarks[i], false));
         }
         if (navigationQueue.Count != 0)
         {
             navigationQueue.RemoveAt(navigationQueue.Count - 1);
         }
     }
     else
     {
         PdfBookmark parentBookmark = navigationQueue[navigationQueue.Count - 2];
         navigationQueue.RemoveAt(navigationQueue.Count - 2);
         UpdateBookmarkList(parentBookmark);
     }
 }
Beispiel #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            //pdf file
            string input = "..\\..\\..\\..\\..\\..\\..\\Data\\Bookmark.pdf";

            //open pdf document
            PdfDocument doc = new PdfDocument(input);

            //get the first bookmark
            PdfBookmark bookmark = doc.Bookmarks[0];

            //change the title of the bookmark
            bookmark.Title = "Modified BookMarks";

            //set the color of the bookmark
            bookmark.Color = Color.Black;

            //set the outline text style of the bookmark
            bookmark.DisplayStyle = PdfTextStyle.Bold;

            //edit child bookmarks of parent bookmark
            EditChildBookmark(bookmark);

            string output = "UpdateBookmark.pdf";

            //save pdf document
            doc.SaveToFile(output);

            //Launching the Pdf file
            PDFDocumentViewer(output);
        }
Beispiel #7
0
        private void AddBookMark(TreeNode parent, PdfBookmark bookMark)
        {
            var node = new TreeNode(bookMark.Text)
            {
                ForeColor  = bookMark.Color,
                Tag        = bookMark,
                ImageIndex = 0
            };

            if (parent == null)
            {
                _treeBookmarks.Nodes.Add(node);
            }
            else
            {
                parent.Nodes.Add(node);
            }

            if (bookMark.Children == null)
            {
                return;
            }
            foreach (var bm in bookMark.Children)
            {
                AddBookMark(node, bm);
            }
        }
Beispiel #8
0
        private void BackToParentButton_TouchUpInside(object sender, EventArgs e)
        {
            PdfBookmark bookmark = parentView.listViewItemsSource[0].Bookmark;

            parentView.listViewItemsSource.Clear();
            if (navigationQueue.Count < 2)
            {
                for (int i = 0; i < parentView.loadedDocument.Bookmarks.Count; i++)
                {
                    parentView.listViewItemsSource.Add(new CustomBookmark(parentView.loadedDocument.Bookmarks[i], false));
                }
                parentView.bookmarkToolbar.bookmarkListView.ReloadData();
                if (navigationQueue.Count != 0)
                {
                    navigationQueue.RemoveAt(navigationQueue.Count - 1);
                }
            }
            else
            {
                //Get the bookmark that was added to the list when the expand button was clicked
                PdfBookmark parentBookmark = navigationQueue[navigationQueue.Count - 2];
                navigationQueue.RemoveAt(navigationQueue.Count - 2);
                UpdateBookmarkList(parentBookmark);
            }
        }
Beispiel #9
0
        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            document = new PdfDocument();
            font     = new PdfStandardFont(PdfFontFamily.Helvetica, 10f);
            brush    = PdfBrushes.Black;

            for (int i = 1; i <= 6; i++)
            {
                PdfPage pages = document.Pages.Add();
                //Add bookmark in PDF document
                PdfBookmark bookmark = AddBookmark(pages, "Chapter " + i, new PointF(10, 10));
                //Add sections to bookmark
                PdfBookmark section1 = AddSection(bookmark, pages, "Section " + i + ".1", new PointF(30, 30), false);
                PdfBookmark section2 = AddSection(bookmark, pages, "Section " + i + ".2", new PointF(30, 400), false);
                //Add subsections to section
                PdfBookmark subsection1 = AddSection(section1, pages, "Paragraph " + i + ".1.1", new PointF(50, 50), true);
                PdfBookmark subsection2 = AddSection(section1, pages, "Paragraph " + i + ".1.2", new PointF(50, 150), true);
                PdfBookmark subsection3 = AddSection(section1, pages, "Paragraph " + i + ".1.3", new PointF(50, 250), true);
                PdfBookmark subsection4 = AddSection(section2, pages, "Paragraph " + i + ".2.1", new PointF(50, 420), true);
                PdfBookmark subsection5 = AddSection(section2, pages, "Paragraph " + i + ".2.2", new PointF(50, 560), true);
                PdfBookmark subsection6 = AddSection(section2, pages, "Paragraph " + i + ".2.3", new PointF(50, 680), true);
            }
            MemoryStream stream = new MemoryStream();
            await document.SaveAsync(stream);

            document.Close(true);
            Save(stream, "Barcode.pdf");
        }
Beispiel #10
0
        //Handles the click event of the expand button of a bookmark. The expand button is visible only for bookmark with children
        private void BookmarkExpand_Clicked(object sender, EventArgs e)
        {
            PdfBookmark bookmark = ((sender as SfFontButton).CommandParameter as CustomBookmark).Bookmark;

            navigationQueue.Add(bookmark);
            UpdateBookmarkList(bookmark);
        }
Beispiel #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Load a pdf document
            string      input = @"..\..\..\..\..\..\Data\UpdateBookmark.pdf";
            PdfDocument doc   = new PdfDocument();

            doc.LoadFromFile(input);

            //Get the first bookmark
            PdfBookmark bookmark = doc.Bookmarks[0];

            //Change the title of the bookmark
            bookmark.Title = "Modified BookMark";

            //Set the color of the bookmark
            bookmark.Color = Color.Black;

            //Set the outline text style of the bookmark
            bookmark.DisplayStyle = PdfTextStyle.Bold;

            //Edit child bookmarks of the parent bookmark
            EditChildBookmark(bookmark);

            //Save the pdf document
            string output = "UpdateBookmark.pdf";

            doc.SaveToFile(output);

            //Launch the file
            PDFDocumentViewer(output);
        }
Beispiel #12
0
        private void ExpandButton_Click(object sender, EventArgs e)
        {
            PdfBookmark bookmark = (sender as CustomButton).Bookmark;

            navigationQueue.Add(bookmark);
            UpdateBookmarkList(bookmark);
        }
Beispiel #13
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a new PDF document.
            PdfDocument doc = new PdfDocument();

            //Load the file from disk.
            doc.LoadFromFile(@"..\..\..\..\..\..\Data\Template_Pdf_1.pdf");

            //Get bookmarks collections of the PDF file.
            PdfBookmarkCollection bookmarks = doc.Bookmarks;

            //Get the page number of the first bookmark.
            PdfBookmark bookmark   = bookmarks[0];
            int         pageNumber = doc.Pages.IndexOf(bookmark.Destination.Page) + 1;

            //Save to file.
            string showPageNumber = pageNumber.ToString();

            String result = "GetPdfBookmarkPageNumber.txt";

            //Save to file.
            File.WriteAllText(result, "The page number of the first bookmark is: " + showPageNumber);

            //Launch the file.
            DocumentViewer(result);
        }
Beispiel #14
0
 private void EditChild2Bookmark(PdfBookmark childBookmark)
 {
     foreach (PdfBookmark child2Bookmark in childBookmark)
     {
         child2Bookmark.Color        = Color.LightSalmon;
         child2Bookmark.DisplayStyle = PdfTextStyle.Italic;
     }
 }
Beispiel #15
0
 private void _show2ndBookmark_Click(object sender, EventArgs e)
 {
     if (pdfViewer1.Document.Bookmarks.Count > 1)
     {
         PdfBookmark bm = pdfViewer1.Document.Bookmarks[2];
         pdfViewer1.ShowPageOfBookmark(bm);
     }
 }
Beispiel #16
0
        private void ExpandButton_TouchUpInside(object sender, EventArgs e)
        {
            int         index    = (int)(sender as UIButton).Tag;
            PdfBookmark bookmark = parentView.listViewItemsSource[index].Bookmark;

            //Add the current bookmark so that it can be used when back button is clicked later
            navigationQueue.Add(bookmark);
            UpdateBookmarkList(bookmark);
        }
Beispiel #17
0
 //Update the listview with new bookmarks when the backtoparent or expand button is clicked
 internal void UpdateBookmarkList(PdfBookmark bookmark)
 {
     listViewItemsSource.Clear();
     listViewItemsSource.Add(new CustomBookmark(bookmark, true));
     for (int i = 0; i < bookmark.Count; i++)
     {
         listViewItemsSource.Add(new CustomBookmark(bookmark[i], false));
     }
 }
Beispiel #18
0
 private void EditChildBookmark(PdfBookmark parentBookmark)
 {
     foreach (PdfBookmark childBookmark in parentBookmark)
     {
         childBookmark.Color        = Color.Blue;
         childBookmark.DisplayStyle = PdfTextStyle.Regular;
         EditChild2Bookmark(childBookmark);
     }
 }
        public static PdfBookmark GetLeftMostDescendant(this PdfBookmark bookmark)
        {
            while (bookmark.Childs?.Count > 0)
            {
                bookmark = bookmark.Childs[0];
            }

            return(bookmark);
        }
Beispiel #20
0
        public void OnClick(View v)
        {
            PdfBookmark bookmark = ((CustomBookmark)v.Tag).Bookmark;

            bookmarkToolbar.sampleView.pdfViewerControl.GoToBookmark(bookmark);
            if (!bookmarkToolbar.sampleView.IsDeviceTablet)
            {
                bookmarkToolbar.sampleView.CollapseBookmarkToolbar();
            }
        }
Beispiel #21
0
 internal void UpdateBookmarkList(PdfBookmark bookmark)
 {
     bookmarkList.Clear();
     bookmarkList.Add(new CustomBookmark(bookmark, true));
     for (int i = 0; i < bookmark.Count; i++)
     {
         bookmarkList.Add(new CustomBookmark(bookmark[i], false));
     }
     NotifyDataSetChanged();
 }
Beispiel #22
0
 //Updates the tableview with the new bookmark list when backtoparent button or expand button is clicked
 internal void UpdateBookmarkList(PdfBookmark bookmark)
 {
     parentView.listViewItemsSource.Clear();
     parentView.listViewItemsSource.Add(new CustomBookmark(bookmark, true));
     for (int i = 0; i < bookmark.Count; i++)
     {
         parentView.listViewItemsSource.Add(new CustomBookmark(bookmark[i], false));
     }
     parentView.bookmarkToolbar.bookmarkListView.ReloadData();
 }
        private void TvBookmark_MenuItem_PDFExtract(object sender,
                                                    RoutedEventArgs e)
        {
            PdfBookmark bookmark = (PdfBookmark)tvBookmarks.SelectedItem;

            if (bookmark == null)
            {
                return;
            }

            IPDFViewer.ExtractBookmark(bookmark);
        }
        private void TvBookmarks_MenuItem_GoTo(object sender,
                                               RoutedEventArgs e)
        {
            PdfBookmark bookmark = (PdfBookmark)tvBookmarks.SelectedItem;

            if (bookmark == null)
            {
                return;
            }

            IPDFViewer.ProcessBookmark(bookmark);
        }
Beispiel #25
0
        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            if (pdfViewer1.Document.Bookmarks.Count > 1)
            {
                var lala = pdfViewer1.Document.Bookmarks.GetAll().GetEnumerator();
                lala.MoveNext();
                lala.MoveNext();

                PdfBookmark bm = lala.Current;
                pdfViewer1.ShowPageOfBookmark(bm);
            }
        }
        private void TvBookmarks_MouseDoubleClick(object sender,
                                                  MouseButtonEventArgs e)
        {
            PdfBookmark bookmark = (PdfBookmark)tvBookmarks.SelectedItem;

            if (bookmark == null)
            {
                return;
            }

            IPDFViewer.ProcessBookmark(bookmark);
        }
        private void bookmarkBtn_Click(object sender, RoutedEventArgs e)
        {
            changeFile = true; //should fix
            int pageIndex = PageConboBox.SelectedIndex;
            //Creates document bookmarks.
            PdfBookmark bookmark = pdfFileBookmark.Bookmarks.Add($"Page {pageIndex + 1}");

            // Sets the destination page.
            bookmark.Destination = new PdfDestination(pdfFileBookmark.Pages[pageIndex]);
            //Set the page and location of the bookmark
            bookmark.Destination.Location = new PointF(0, 0);
            bookmarkList.Add(bookmark);
        }
        public static string ToHierarchyString(this PdfBookmark bookmark)
        {
            List <PdfBookmark> bookmarkHierarchy = new List <PdfBookmark>();

            do
            {
                bookmarkHierarchy.Add(bookmark);
            } while ((bookmark = bookmark.Parent) != null);

            bookmarkHierarchy.Reverse();

            return(StringEx.Join("::", bookmarkHierarchy.Select(b => b.Title)));
        }
        /// <summary>
        /// Navigates the control to a bookmark
        /// </summary>
        void GoToBookmark()
        {
            PdfLoadedDocument pdfLoadedDocument = pdfViewer.LoadedDocument;

            //Get the complete bookmarks in the PDF.
            PdfBookmarkBase bookmarks = pdfLoadedDocument.Bookmarks;

            //In this example, we get the first bookmark in the PDF bookmarks collection at the index of 0.
            PdfBookmark firstBookmark = bookmarks[0];

            //Navigates to the first bookmark present in the PDF.
            pdfViewer.GoToBookmark(firstBookmark);
        }
Beispiel #30
0
        void GenerateBookmarks(AugmentedPdfLoadedDocument doc, PdfBookmarkBase bookmark_base, int depth)
        {
            // Don't go too deep in the bookmark hierarchy
            if (depth > 0)
            {
                return;
            }

            int last_start_page = 0;

            for (int i = 0; i < bookmark_base.Count; ++i)
            {
                PdfBookmark bookmark    = bookmark_base[i];
                int         page_number = -1;
                if (null != bookmark.Destination)
                {
                    if (-1 == page_number)
                    {
                        for (int j = last_start_page; j < doc.Pages.Count; ++j)
                        {
                            if (doc.Pages[j] == bookmark.Destination.Page)
                            {
                                page_number     = j;
                                last_start_page = j;
                                break;
                            }
                        }
                    }

                    if (-1 == page_number)
                    {
                        for (int j = 0; j < last_start_page; ++j)
                        {
                            if (doc.Pages[j] == bookmark.Destination.Page)
                            {
                                page_number     = j;
                                last_start_page = j;
                                break;
                            }
                        }
                    }
                }

                if (-1 != page_number)
                {
                    popup.Children.Add(new JumpToSectionItem(popup, popup.pdf_reading_control, popup.pdf_render_control, popup.pdf_renderer_control_stats, bookmark.Title, page_number + 1));
                }

                GenerateBookmarks(doc, bookmark, depth + 1);
            }
        }
Beispiel #31
0
        private PdfBookmark LoadBookmark(IntPtr bookmark)
        {
            var result = new PdfBookmark
            {
                Title = GetBookmarkTitle(bookmark),
                PageIndex = (int)GetBookmarkPageIndex(bookmark)
            };

            //Action = NativeMethods.FPDF_BookmarkGetAction(_bookmark);
            //if (Action != IntPtr.Zero)
            //    ActionType = NativeMethods.FPDF_ActionGetType(Action);

            var child = NativeMethods.FPDF_BookmarkGetFirstChild(_document, bookmark);
            if (child != IntPtr.Zero)
                LoadBookmarks(result.Children, child);

            return result;
        }
Beispiel #32
0
 private TreeNode GetBookmarkNode(PdfBookmark bookmark)
 {
     TreeNode node = new TreeNode(bookmark.Title);
     node.Tag = bookmark;
     if (bookmark.Children != null)
     {
         foreach (var child in bookmark.Children)
             node.Nodes.Add(GetBookmarkNode(child));
     }
     return node;
 }