private void GetChildBookmarks(PdfBookmarkCollection bookmarks, string result) { //Declare a new StringBuilder content StringBuilder content = new StringBuilder(); //Get Pdf child Bookmarks information. foreach (PdfBookmark parentBookmark in bookmarks) { if (parentBookmark.Count > 0) { content.AppendLine("Child Bookmarks:"); foreach (PdfBookmark childBookmark in parentBookmark) { //Get the title content.AppendLine(childBookmark.Title); //Get the color. string color = childBookmark.Color.ToString(); content.AppendLine(color); //Get the text style. string textStyle = childBookmark.DisplayStyle.ToString(); content.AppendLine(textStyle); } } //Save to file. File.WriteAllText(result, content.ToString()); } }
protected void LoadDocument(IntPtr document) { _document = document; NativeMethods.FPDF_GetDocPermissions(_document); _formCallbacks = new NativeMethods.FPDF_FORMFILLINFO(); _formCallbacksHandle = GCHandle.Alloc(_formCallbacks, GCHandleType.Pinned); // Depending on whether XFA support is built into the PDFium library, the version // needs to be 1 or 2. We don't really care, so we just try one or the other. for (var i = 1; i <= 2; i++) { _formCallbacks.version = i; _form = NativeMethods.FPDFDOC_InitFormFillEnvironment(_document, _formCallbacks); if (_form != IntPtr.Zero) { break; } } NativeMethods.FPDF_SetFormFieldHighlightColor(_form, 0, 0xFFE4DD); NativeMethods.FPDF_SetFormFieldHighlightAlpha(_form, 100); NativeMethods.FORM_DoDocumentJSAction(_form); NativeMethods.FORM_DoDocumentOpenAction(_form); Bookmarks = new PdfBookmarkCollection(); LoadBookmarks(Bookmarks, NativeMethods.FPDF_BookmarkGetFirstChild(document, IntPtr.Zero)); }
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); }
protected void LoadDocument(IntPtr doc) { _document = doc; PdfiumLibrary.FPDF_GetDocPermissions(_document); _formCallbacks = new API.FPDF_FORMFILLINFO(); _formCallbacksHandle = GCHandle.Alloc(_formCallbacks, GCHandleType.Pinned); for (int i = 1; i <= 2; i++) { _formCallbacks.version = i; _form = PdfiumLibrary.FPDFDOC_InitFormFillEnvironment(_document, _formCallbacks); if (_form != IntPtr.Zero) { break; } } PdfiumLibrary.FPDF_SetFormFieldHighlightColor(_form, 0, 0xFFE4DD); PdfiumLibrary.FPDF_SetFormFieldHighlightAlpha(_form, 100); PdfiumLibrary.FORM_DoDocumentJSAction(_form); PdfiumLibrary.FORM_DoDocumentOpenAction(_form); Bookmarks = new PdfBookmarkCollection(); LoadBookmarks(Bookmarks, PdfiumLibrary.FPDFBookmark_GetFirstChild(_document, IntPtr.Zero)); }
private PdfBookmarkCollection TranslateBookmarks(PdfBookmarkCollection bookmarks) { var result = new PdfBookmarkCollection(); TranslateBookmarks(result, bookmarks); return(result); }
private static void GetBookmarkText(StringBuilder sb, PdfBookmarkCollection bookmarks) { foreach (var bookmark in bookmarks) { sb.AppendLine(bookmark.Title); if (bookmark.Children != null) { GetBookmarkText(sb, bookmark.Children); } } }
private void LoadBookmarks(PdfBookmarkCollection bookmarks, IntPtr bookmark) { if (bookmark == IntPtr.Zero) { return; } bookmarks.Add(LoadBookmark(bookmark)); while ((bookmark = NativePdfiumMethods.FPDF_BookmarkGetNextSibling(_document, bookmark)) != IntPtr.Zero) { bookmarks.Add(LoadBookmark(bookmark)); } }
private void LoadBookmarks(PdfBookmarkCollection bookmarks, IntPtr bookmark) { if (bookmark == IntPtr.Zero) { return; } bookmarks.Add(LoadBookmark(bookmark)); while ((bookmark = PdfiumLibrary.FPDFBookmark_GetNextSibling(_document, bookmark)) != IntPtr.Zero) { bookmarks.Add(LoadBookmark(bookmark)); } }
static void Main(string[] args) { //Initialize an instance of PdfDocument class and load the PDF file PdfDocument pdf = new PdfDocument(); pdf.LoadFromFile(@"C:\Users\Administrator\Desktop\Bookmark1.pdf"); //Get all bookmarks and remove the first one PdfBookmarkCollection bookmarks = pdf.Bookmarks; bookmarks.RemoveAt(0); //Save to file and open the document pdf.SaveToFile("DemoveBookmark.pdf"); System.Diagnostics.Process.Start("DemoveBookmark.pdf"); }
private static void __Execute(atom.Trace context, int level, PdfBookmarkCollection data) { if (data != null) { foreach (var a_Context in data) { context. SetComment("[[[Page]]]: " + (a_Context.PageIndex + 1).ToString(), "[[[Page index]]]"). Send(NAME.SOURCE.PREVIEW, NAME.TYPE.PARAMETER, level, a_Context.Title); if (a_Context.Children?.Count > 0) { __Execute(context, level + 1, a_Context.Children); } } } }
public String GetBookmarksText() { if (pdfViewer.Document != null) { StringBuilder sb = new StringBuilder(); PdfBookmarkCollection bookmarks = pdfViewer.Document.Bookmarks; GetBookmarkText(sb, bookmarks); if (sb.Length > 0) { return(sb.ToString()); } } return(null); }
private void TranslateBookmarks(PdfBookmarkCollection result, PdfBookmarkCollection bookmarks) { foreach (var bookmark in bookmarks) { if (bookmark.PageIndex >= _startPage && bookmark.PageIndex <= _endPage) { var resultBookmark = new PdfBookmark { PageIndex = bookmark.PageIndex - _startPage, Title = bookmark.Title }; TranslateBookmarks(resultBookmark.Children, bookmark.Children); result.Add(resultBookmark); } } }
private PdfBookmarkCollection LoadBookmarks(IntPtr bookmark) { var result = new PdfBookmarkCollection(); if (bookmark == IntPtr.Zero) { return(result); } result.Add(LoadBookmark(bookmark)); while ((bookmark = NativeMethods.FPDF_BookmarkGetNextSibling(_document, bookmark)) != IntPtr.Zero) { result.Add(LoadBookmark(bookmark)); } return(result); }
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; string result = "GetPdfChildBookmarks_out.txt"; //Get Pdf child Bookmarks. GetChildBookmarks(bookmarks, result); //Launch the file. DocumentViewer(result); }
protected void LoadDocument(IntPtr document) { _document = document; NativePdfiumMethods.FPDF_GetDocPermissions(_document); _formCallbacks = new NativePdfiumMethods.FPDF_FORMFILLINFO(); _formCallbacksHandle = GCHandle.Alloc(_formCallbacks); _formCallbacks.version = 1; _form = NativePdfiumMethods.FPDFDOC_InitFormFillEnvironment(_document, ref _formCallbacks); NativePdfiumMethods.FPDF_SetFormFieldHighlightColor(_form, 0, 0xFFE4DD); NativePdfiumMethods.FPDF_SetFormFieldHighlightAlpha(_form, 100); NativePdfiumMethods.FORM_DoDocumentJSAction(_form); NativePdfiumMethods.FORM_DoDocumentOpenAction(_form); Bookmarks = new PdfBookmarkCollection(); LoadBookmarks(Bookmarks, NativePdfiumMethods.FPDF_BookmarkGetFirstChild(document, IntPtr.Zero)); }
static void Main(string[] args) { //Initialize an instance of PdfDocument class and load the PDF file PdfDocument pdf = new PdfDocument(); pdf.LoadFromFile(@"C:\Users\Administrator\Desktop\Bookmark.pdf"); //Get the first bookmark PdfBookmarkCollection bookmarks = pdf.Bookmarks; PdfBookmark childbookmark = bookmarks[0]; //Modify the bookmark font and color in the appointed bookmark of the page childbookmark.Destination = new PdfDestination(pdf.Pages[1]); childbookmark.DisplayStyle = PdfTextStyle.Bold; childbookmark.Color = Color.Brown; //Modify the title of bookmark childbookmark.Title = "CHAPER Ⅰ"; //Save to file and open the document pdf.SaveToFile("ModifyBookmark.pdf"); System.Diagnostics.Process.Start("ModifyBookmark.pdf"); }
private void button1_Click(object sender, EventArgs e) { //Create a new PDF document PdfDocument pdfdoc = new PdfDocument(); //load the document from disk pdfdoc.LoadFromFile(@"..\..\..\..\..\..\Data\Template_Pdf_1.pdf"); //Get bookmarks collections of the PDF file PdfBookmarkCollection bookmarks = pdfdoc.Bookmarks; //Set Zoom level as 0, which the value is inherit zoom foreach (PdfBookmark bookMark in bookmarks) { bookMark.Destination.Zoom = 0.5f; } String result = "SetInheritZoom_out.pdf"; //Save the document pdfdoc.SaveToFile(result); //Launch the Pdf file PDFDocumentViewer(result); }
public PdfBookmark() { Children = new PdfBookmarkCollection(); }
protected void LoadDocument(IntPtr document) { _document = document; NativeMethods.FPDF_GetDocPermissions(_document); _formCallbacks = new NativeMethods.FPDF_FORMFILLINFO(); _formCallbacksHandle = GCHandle.Alloc(_formCallbacks); _formCallbacks.version = 1; _form = NativeMethods.FPDFDOC_InitFormFillEnvironment(_document, ref _formCallbacks); NativeMethods.FPDF_SetFormFieldHighlightColor(_form, 0, 0xFFE4DD); NativeMethods.FPDF_SetFormFieldHighlightAlpha(_form, 100); NativeMethods.FORM_DoDocumentJSAction(_form); NativeMethods.FORM_DoDocumentOpenAction(_form); Bookmarks = new PdfBookmarkCollection(); LoadBookmarks(Bookmarks, NativeMethods.FPDF_BookmarkGetFirstChild(document, IntPtr.Zero)); }
private void LoadBookmarks(PdfBookmarkCollection bookmarks, IntPtr bookmark) { if (bookmark == IntPtr.Zero) return; bookmarks.Add(LoadBookmark(bookmark)); while ((bookmark = NativeMethods.FPDF_BookmarkGetNextSibling(_document, bookmark)) != IntPtr.Zero) bookmarks.Add(LoadBookmark(bookmark)); }