//////////////////////////////////////////////////////////////////// /// <summary> /// Gets child bookmark /// </summary> /// <param name="IndexArray">Array of indices</param> /// <returns>Child bookmark or null if not found.</returns> /// <remarks> /// Gets PdfBookmark object based on index. /// You can have multiple indices separated by commas /// i.e. GetChild(2, 3); /// Index is zero based. In the example we are looking first for /// the third bookmark child and then the forth bookmark of the /// next level. /// </remarks> //////////////////////////////////////////////////////////////////// public PdfBookmark GetChild ( params int[] IndexArray ) { var Bookmark = this; PdfBookmark Child = null; for (var Level = 0; Level < IndexArray.Length; Level++, Bookmark = Child) { // get index number for level var Index = IndexArray[Level]; // find the child at this level with the given index for (Child = Bookmark.FirstChild; Index > 0 && Child != null; Child = Child.NextSibling, Index--) { ; } // not found if (Child == null) { return(null); } } return(Child); }
//////////////////////////////////////////////////////////////////// /// <summary> /// Gets bookmarks root /// </summary> /// <returns>Root bookmark object</returns> //////////////////////////////////////////////////////////////////// public PdfBookmark GetBookmarksRoot() { // create bookmarks root node if this is the first time if (BookmarksRoot == null) { BookmarksRoot = new PdfBookmark(this); } // return bookmarks node to the user return(BookmarksRoot); }
//////////////////////////////////////////////////////////////////// /// <summary> /// Add child bookmark /// </summary> /// <param name="Title">Bookmark title.</param> /// <param name="Page">Page</param> /// <param name="XPos">Horizontal position</param> /// <param name="YPos">Vertical position.</param> /// <param name="Zoom">Zoom factor (1.0 is 100%. 0.0 is no change from existing zoom).</param> /// <param name="Paint">Bookmark color.</param> /// <param name="TextStyle">Bookmark text style.</param> /// <param name="OpenEntries">Open child bookmarks attached to this one.</param> /// <returns>Bookmark object</returns> /// <remarks> /// Add bookmark as a child to this bookmark. /// This method creates a new child bookmark item attached /// to this parent /// </remarks> //////////////////////////////////////////////////////////////////// public PdfBookmark AddBookmark ( string Title, // bookmark title PdfPage Page, // bookmark page double XPos, // bookmark horizontal position relative to bottom left corner of the page double YPos, // bookmark vertical position relative to bottom left corner of the page double Zoom, // Zoom factor. 1.0 is 100%. 0.0 is no change from existing zoom. Color Paint, // bookmark color TextStyle TextStyle, // bookmark text style: normal, bold, italic, bold-italic bool OpenEntries // true is display children. false hide children ) { // create new bookmark var Bookmark = new PdfBookmark(Document, OpenEntries) { // attach to parent Parent = this }; // this bookmark is first child if (FirstChild == null) { FirstChild = Bookmark; LastChild = Bookmark; } // this bookmark is not first child else { LastChild.NextSibling = Bookmark; Bookmark.PrevSibling = LastChild; LastChild = Bookmark; } // the parent of this bookmark displays all children if (this.OpenEntries) { // update count Count++; for (var TestParent = Parent; TestParent != null && TestParent.OpenEntries; TestParent = TestParent.Parent) { TestParent.Count++; } } // the parent of this bookmark does not display all children else { Count--; } // build dictionary Bookmark.Dictionary.AddPdfString("/Title", Title); Bookmark.Dictionary.AddIndirectReference("/Parent", this); Bookmark.Dictionary.AddFormat("/Dest", "[{0} 0 R /XYZ {1} {2} {3}]", Page.ObjectNumber, ToPt(XPos), ToPt(YPos), Round(Zoom)); if (Paint != Color.Empty) { Bookmark.Dictionary.AddFormat("/C", "[{0} {1} {2}]", Round(Paint.R / 255.0), Round(Paint.G / 255.0), Round(Paint.B / 255.0)); } if (TextStyle != TextStyle.Normal) { Bookmark.Dictionary.AddInteger("/F", (int)TextStyle); } return(Bookmark); }
//////////////////////////////////////////////////////////////////// /// <summary> /// Gets bookmarks root /// </summary> /// <returns>Root bookmark object</returns> //////////////////////////////////////////////////////////////////// public PdfBookmark GetBookmarksRoot() { // create bookmarks root node if this is the first time if(BookmarksRoot == null) BookmarksRoot = new PdfBookmark(this); // return bookmarks node to the user return(BookmarksRoot); }
//////////////////////////////////////////////////////////////////// /// <summary> /// Add child bookmark /// </summary> /// <param name="Title">Bookmark title.</param> /// <param name="Page">Page</param> /// <param name="XPos">Horizontal position</param> /// <param name="YPos">Vertical position.</param> /// <param name="Zoom">Zoom factor (1.0 is 100%. 0.0 is no change from existing zoom).</param> /// <param name="Paint">Bookmark color.</param> /// <param name="TextStyle">Bookmark text style.</param> /// <param name="OpenEntries">Open child bookmarks attached to this one.</param> /// <returns>Bookmark object</returns> /// <remarks> /// Add bookmark as a child to this bookmark. /// This method creates a new child bookmark item attached /// to this parent /// </remarks> //////////////////////////////////////////////////////////////////// public PdfBookmark AddBookmark( String Title, // bookmark title PdfPage Page, // bookmark page Double XPos, // bookmark horizontal position relative to bottom left corner of the page Double YPos, // bookmark vertical position relative to bottom left corner of the page Double Zoom, // Zoom factor. 1.0 is 100%. 0.0 is no change from existing zoom. Color Paint, // bookmark color TextStyle TextStyle, // bookmark text style: normal, bold, italic, bold-italic Boolean OpenEntries // true is display children. false hide children ) { // create new bookmark PdfBookmark Bookmark = new PdfBookmark(Document, OpenEntries); // attach to parent Bookmark.Parent = this; // this bookmark is first child if(FirstChild == null) { FirstChild = Bookmark; LastChild = Bookmark; } // this bookmark is not first child else { LastChild.NextSibling = Bookmark; Bookmark.PrevSibling = LastChild; LastChild = Bookmark; } // the parent of this bookmark displays all children if(this.OpenEntries) { // update count Count++; for(PdfBookmark TestParent = Parent; TestParent != null && TestParent.OpenEntries; TestParent = TestParent.Parent) TestParent.Count++; } // the parent of this bookmark does not display all children else { Count--; } // build dictionary Bookmark.Dictionary.AddPdfString("/Title", Title); Bookmark.Dictionary.AddIndirectReference("/Parent", this); Bookmark.Dictionary.AddFormat("/Dest", "[{0} 0 R /XYZ {1} {2} {3}]", Page.ObjectNumber, ToPt(XPos), ToPt(YPos), (Single) Zoom); if(Paint != Color.Empty) Bookmark.Dictionary.AddFormat("/C", "[{0} {1} {2}]", Round((Double) Paint.R / 255.0), Round((Double) Paint.G / 255.0), Round((Double) Paint.B / 255.0)); if(TextStyle != TextStyle.Normal) Bookmark.Dictionary.AddInteger("/F", (Int32) TextStyle); return(Bookmark); }