/// <summary> /// Initializes a new instance of the <see cref="PDFBookmark"/> class. /// </summary> /// <param name="mainComponent">Main component where this bookmark belongs.</param> /// <param name="bookmarkHandle">Handle of this bookmark.</param> public PDFBookmark(PDFComponent mainComponent, FPDF_BOOKMARK bookmarkHandle) { _mainComponent = mainComponent ?? throw new ArgumentNullException(nameof(mainComponent)); _bookmarkHandle = bookmarkHandle; Bookmarks = new ObservableCollection <IPDFBookmark>(); }
/// <summary> /// Get the title of |bookmark|. /// </summary> /// <param name="bookmark">Handle to the bookmark.</param> /// <param name="buffer">Buffer for the title. May be NULL.</param> /// <param name="buflen">The length of the buffer in bytes. May be 0.</param> /// <returns>Returns the number of bytes in the title, including the terminating NUL character. /// The number of bytes is returned regardless of the |buffer| and |buflen| parameters.</returns> /// <remarks> /// Regardless of the platform, the |buffer| is always in UTF-16LE encoding. The string is terminated by a UTF16 NUL character. /// If |buflen| is less than the required length, or |buffer| is NULL, |buffer| will not be modified. /// FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFBookmark_GetTitle(FPDF_BOOKMARK bookmark, void* buffer, unsigned long buflen);. /// </remarks> public int FPDFBookmark_GetTitle(FPDF_BOOKMARK bookmark, IntPtr buffer, ulong buflen) { lock (_syncObject) { return(FPDFBookmark_GetTitleStatic(bookmark, buffer, buflen)); } }
/// <summary> /// Get the next sibling of |bookmark|. /// </summary> /// <param name="document">Handle to the document.</param> /// <param name="bookmark">Handle to the current bookmark.</param> /// <returns>Returns a handle to the next sibling of |bookmark|, or NULL if this is the last bookmark at this level.</returns> /// <remarks> /// Note that the caller is responsible for handling circular bookmark references, as may arise from malformed documents. /// FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark);. /// </remarks> public FPDF_BOOKMARK FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark) { lock (_syncObject) { return(FPDFBookmark_GetNextSiblingStatic(document, bookmark)); } }
/// <summary> /// Get the first child of |bookmark|, or the first top-level bookmark item. /// </summary> /// <param name="document">Handle to the document.</param> /// <param name="bookmark">Handle to the current bookmark. Pass NULL for the first top level item.</param> /// <returns>Returns a handle to the first child of |bookmark| or the first top-level bookmark item. NULL if no child or top-level bookmark found.</returns> /// <remarks> /// FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark);. /// </remarks> public FPDF_BOOKMARK FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark) { lock (_syncObject) { return(FPDFBookmark_GetFirstChildStatic(document, bookmark)); } }
/// <summary> /// Get the action associated with |bookmark|. /// </summary> /// <param name="bookmark">Handle to the bookmark.</param> /// <returns>Returns the handle to the action data, or NULL if no action is associated with |bookmark|. /// When NULL is returned, FPDFBookmark_GetDest() should be called to get the |bookmark| destination data.</returns> /// <remarks> /// FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV FPDFBookmark_GetAction(FPDF_BOOKMARK bookmark);. /// </remarks> public FPDF_ACTION FPDFBookmark_GetAction(FPDF_BOOKMARK bookmark) { lock (_syncObject) { return(FPDFBookmark_GetActionStatic(bookmark)); } }
/// <summary> /// Get the destination associated with |bookmark|. /// </summary> /// <param name="document">Handle to the document.</param> /// <param name="bookmark">Handle to the bookmark.</param> /// <returns>Returns the handle to the destination data, NULL if no destination is associated with |bookmark|.</returns> /// <remarks> /// FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFBookmark_GetDest(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark);. /// </remarks> public FPDF_DEST FPDFBookmark_GetDest(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark) { lock (_syncObject) { return(FPDFBookmark_GetDestStatic(document, bookmark)); } }
private static string BookmarkTitle(PDFiumBridge bridge, FPDF_BOOKMARK bookmark) { var len = bridge.FPDFBookmark_GetTitle(bookmark, IntPtr.Zero, 0); var buffer = Marshal.AllocHGlobal(len); var returnedLen = bridge.FPDFBookmark_GetTitle(bookmark, buffer, (ulong)len); Assert.AreEqual(len, returnedLen); var title = Marshal.PtrToStringUni(buffer); Marshal.FreeHGlobal(buffer); return(title); }
private static void FindSibling( PDFiumBridge bridge, FPDF_DOCUMENT document, FPDF_BOOKMARK bookmarkPrevSibling, ref int countOfBookmarks) { var nextSibling = bridge.FPDFBookmark_GetNextSibling(document, bookmarkPrevSibling); if (nextSibling.IsValid) { countOfBookmarks++; CheckBookmark(bridge, document, nextSibling); FindFirstChild(bridge, document, nextSibling, ref countOfBookmarks); FindSibling(bridge, document, nextSibling, ref countOfBookmarks); } }
private static void FindFirstChild( PDFiumBridge bridge, FPDF_DOCUMENT document, FPDF_BOOKMARK bookmarkParent, ref int countOfBookmarks) { var firstChild = bridge.FPDFBookmark_GetFirstChild(document, bookmarkParent); if (firstChild.IsValid) { countOfBookmarks++; CheckBookmark(bridge, document, firstChild); FindFirstChild(bridge, document, firstChild, ref countOfBookmarks); FindSibling(bridge, document, firstChild, ref countOfBookmarks); } }
/// <summary> /// Get the title of <paramref name="bookmark" />. /// </summary> /// <param name="bookmark">Handle to the bookmark.</param> /// <returns>The title of the bookmark.</returns> public static string FPDFBookmark_GetTitle(FPDF_BOOKMARK bookmark) => GetUtf16String((ref byte buffer, int length) => (int)FPDFBookmark_GetTitle(bookmark, ref buffer, (uint)length), sizeof(byte), true);
public void FPDF_BOOKMARK_Constructor_Call2_Success() { var h = new FPDF_BOOKMARK(new IntPtr(1)); Assert.IsTrue(h.IsValid); }
public void FPDF_BOOKMARK_Constructor_Call1_Success() { var h = new FPDF_BOOKMARK(); Assert.IsFalse(h.IsValid); }
private static void CheckBookmark(PDFiumBridge bridge, FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark) { var title = BookmarkTitle(bridge, bookmark); Assert.IsFalse(string.IsNullOrEmpty(title)); var action = bridge.FPDFBookmark_GetAction(bookmark); Assert.IsTrue(action.IsValid); var actionDestination = bridge.FPDFAction_GetDest(document, action); Assert.IsTrue(actionDestination.IsValid); var actionDestinationPage = bridge.FPDFDest_GetDestPageIndex(document, actionDestination); var resultA = bridge.FPDFDest_GetLocationInPage(actionDestination, out bool hasXValA, out bool hasYValA, out bool hasZoomValA, out float xA, out float yA, out float zoomA); Assert.IsTrue(resultA); var destination = bridge.FPDFBookmark_GetDest(document, bookmark); Assert.IsTrue(destination.IsValid); var destinationPage = bridge.FPDFDest_GetDestPageIndex(document, destination); var resultB = bridge.FPDFDest_GetLocationInPage(actionDestination, out bool hasXValB, out bool hasYValB, out bool hasZoomValB, out float xB, out float yB, out float zoomB); Assert.IsTrue(resultB); Assert.AreEqual(hasXValA, hasXValB); Assert.AreEqual(hasYValA, hasYValB); Assert.AreEqual(hasZoomValA, hasZoomValB); Assert.AreEqual(xA, xB); Assert.AreEqual(yA, yB); Assert.AreEqual(zoomA, zoomB); Assert.AreEqual(actionDestinationPage, destinationPage); }