//Populate the bookmark toolbar with the bookmarks when a new PDF is loaded internal void PopulateInitialBookmarkList() { listViewItemsSource.Clear(); PdfBookmarkBase bookmarkBase = bookmarkLoadedDocument.Bookmarks; for (int i = 0; i < bookmarkBase.Count; i++) { listViewItemsSource.Add(new CustomBookmark(bookmarkBase[i], false)); } }
internal void PopulateInitialBookmarkList() { listAdapter.bookmarkList.Clear(); PdfBookmarkBase bookmarkBase = bookmarkLoadedDocument.Bookmarks; for (int i = 0; i < bookmarkBase.Count; i++) { listAdapter.bookmarkList.Add(new CustomBookmark(bookmarkBase[i], false)); } listAdapter.NotifyDataSetChanged(); }
/// <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); }
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); } }
//Populates the bookmark toolbar with the bookmarks when a PDF is loaded private void PopulateInitialBookmarkList() { listViewItemsSource.Clear(); PdfBookmarkBase bookmarkBase = loadedDocument.Bookmarks; for (int i = 0; i < bookmarkBase.Count; i++) { listViewItemsSource.Add(new CustomBookmark(bookmarkBase[i], false)); } if (bookmarkToolbar != null) { bookmarkToolbar.bookmarkListView.ReloadData(); } }
private async void OpenFileViewerCommand() { var picker = new FileOpenPicker(); picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; picker.ViewMode = PickerViewMode.List; //Filters PDF files in the documents library. picker.FileTypeFilter.Add(".pdf"); var file = await picker.PickSingleFileAsync(); if (file == null) { return; } //Reads the stream of the loaded PDF document. var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); Stream fileStream = stream.AsStreamForRead(); byte[] buffer = new byte[fileStream.Length]; fileStream.Read(buffer, 0, buffer.Length); //Loads the PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument(buffer); //Creates custom progress ring. ProgressRing progressRing = new ProgressRing(); progressRing.Foreground = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 255, 0, 0)); progressRing.Width = 100; progressRing.Height = 100; //Assigns custom progress ring to the Viewer control. pdfViewer.PdfProgressRing = progressRing; pdfViewer.LoadDocument(loadedDocument); //Loadds bookmarks bookmarkBase = loadedDocument.Bookmarks; PdfBookmark bookmark; SfTreeNavigatorItem navigatorItem; //Runs through initial bookmarks for (int i = 0; i < bookmarkBase.Count; i++) { bookmark = bookmarkBase[i] as PdfLoadedBookmark; // Here we create a rootnode for treeview with the command // It includes the child nodes too TreeViewNode rootNode = AddChildBookmarks(bookmark); treeNavigator.ItemInvoked += TreeNavigator_ItemInvoked; treeNavigator.RootNodes.Add(rootNode); } }
/// <summary> /// Navigates the control to the child bookmark of a bookmark /// </summary> void GoToChildBookmark() { PdfLoadedDocument pdfLoadedDocument = pdfViewer.LoadedDocument; //Get the complete bookmarks in the PDF. PdfBookmarkBase bookmarks = pdfLoadedDocument.Bookmarks; //Gets the fourth bookmark in the PDF bookmarks collection at the index of 3. PdfBookmark fourthBookmark = bookmarks[3]; //Check whether it has child bookmarks. if (fourthBookmark.Count > 0) { //Navigates to the first child of the fourth bookmark in the PDF. pdfViewer.GoToBookmark(bookmarks[3][0]); } }
internal void PopulateInitialBookmarkList() { if (listViewItemsSource != null && listViewItemsSource.Count != 0) { try { for (int i = listViewItemsSource.Count - 1; i >= 0; i--) { listViewItemsSource.RemoveAt(i); } } catch (Exception) { } } if (bookmarkLoadedDocument != null) { PdfBookmarkBase bookmarkBase = bookmarkLoadedDocument.Bookmarks; for (int i = 0; i < bookmarkBase.Count; i++) { listViewItemsSource.Add(new CustomBookmark(bookmarkBase[i], false)); } } if (navigationQueue.Count != 0) { try { for (int i = navigationQueue.Count - 1; i >= 0; i--) { navigationQueue.RemoveAt(i); } } catch (Exception) { } } }
static void Main(string[] args) { //Load the PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("../../../../Data/PDF_Succinctly.pdf"); PdfBookmarkBase bookmarks = loadedDocument.Bookmarks; Dictionary <PdfPageBase, int> pages = new Dictionary <PdfPageBase, int>(); Dictionary <string, List <int> > splitRange = new Dictionary <string, List <int> >(); //iterate all the pages and its index for (int i = 0; i < loadedDocument.Pages.Count; i++) { PdfPageBase page = loadedDocument.Pages[i] as PdfPageBase; pages.Add(page, i); } //Iterate all the bookmarks and it is page range for (int i = 0; i < bookmarks.Count; i++) { if (bookmarks[i].Destination != null) { PdfPageBase page = bookmarks[i].Destination.Page; if (pages.ContainsKey(page)) { //Bookmark doesn't have any child bookmark if (bookmarks[i].Count == 0) { int startIndex = pages[page]; List <int> range = new List <int>(); range.Add(startIndex); range.Add(startIndex); splitRange.Add(bookmarks[i].Title, range); } //Bookmark has child bookmark else { int startIndex = pages[page]; int endIndex = startIndex; List <int> range = new List <int>(); foreach (PdfLoadedBookmark bookmark in bookmarks[i]) { PdfPageBase innerPage = bookmark.Destination.Page; if (pages.ContainsKey(innerPage)) { endIndex = pages[innerPage]; } } range.Add(startIndex); range.Add(endIndex); splitRange.Add(bookmarks[i].Title, range); } } } } //Split the PDF document based on the bookmark page range. foreach (string title in splitRange.Keys) { int startIndex = splitRange[title][0]; int endIndex = splitRange[title][1]; //Create a new PDF document. PdfDocument document = new PdfDocument(); //Import the pages to the new PDF document. document.ImportPageRange(loadedDocument, startIndex, endIndex); //Save the document in a specified folder. document.Save(title + ".pdf"); //Close the document. document.Close(true); } loadedDocument.Close(true); }