예제 #1
0
        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);
        }
예제 #2
0
 /// <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));
     }
 }
예제 #3
0
 /// <summary>
 /// Get meta-data |tag| content from |document|.
 /// </summary>
 /// <param name="document">Handle to the document.</param>
 /// <param name="tag">The tag to retrieve. The tag can be one of: Title, Author, Subject, Keywords, Creator, Producer, CreationDate, or ModDate.
 /// For detailed explanations of these tags and their respective values, please refer to PDF Reference 1.6, section 10.2.1, 'Document Information Dictionary'.</param>
 /// <param name="buffer">A buffer for the tag. 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 tag, including trailing zeros.</returns>
 /// <remarks>
 /// The |buffer| is always encoded in UTF-16LE. The |buffer| is followed by two bytes of zeros indicating the end of the string.
 /// If |buflen| is less than the returned length, or |buffer| is NULL, |buffer| will not be modified.
 /// For linearized files, FPDFAvail_IsFormAvail must be called before this, and it must have returned PDF_FORM_AVAIL or PDF_FORM_NOTEXIST.
 /// Before that, there is no guarantee the metadata has been loaded.
 /// FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetMetaText(FPDF_DOCUMENT document, FPDF_BYTESTRING tag, void* buffer, unsigned long buflen);.
 /// </remarks>
 public int FPDF_GetMetaText(FPDF_DOCUMENT document, [MarshalAs(UnmanagedType.LPStr)] string tag, IntPtr buffer, ulong buflen)
 {
     lock (_syncObject)
     {
         return(FPDF_GetMetaTextStatic(document, tag, buffer, buflen));
     }
 }
예제 #4
0
 /// <summary>
 /// Get the page label for |page_index| from |document|.
 /// </summary>
 /// <param name="document">Handle to the document.</param>
 /// <param name="page_index">The 0-based index of the page.</param>
 /// <param name="buffer">A buffer for the page label. 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 page label, including trailing zeros.</returns>
 /// <remarks>
 /// The |buffer| is always encoded in UTF-16LE. The |buffer| is followed by two bytes of zeros indicating the end of the string.
 /// If |buflen| is less than the returned length, or |buffer| is NULL, |buffer| will not be modified.
 /// FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetPageLabel(FPDF_DOCUMENT document, int page_index, void* buffer, unsigned long buflen);.
 /// </remarks>
 public int FPDF_GetPageLabel(FPDF_DOCUMENT document, int page_index, IntPtr buffer, ulong buflen)
 {
     lock (_syncObject)
     {
         return(FPDF_GetPageLabelStatic(document, page_index, buffer, buflen));
     }
 }
예제 #5
0
 /// <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));
     }
 }
예제 #6
0
 /// <summary>
 /// Experimental API.
 /// Get the file identifer defined in the trailer of |document|.
 /// </summary>
 /// <param name="document">Handle to the document.</param>
 /// <param name="id_type">The file identifier type to retrieve.</param>
 /// <param name="buffer">A buffer for the file identifier. 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 file identifier, including the NUL terminator.</returns>
 /// <remarks>
 /// The |buffer| is always a byte string. The |buffer| is followed by a NUL terminator.
 /// If |buflen| is less than the returned length, or |buffer| is NULL, |buffer| will not be modified.
 /// FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetFileIdentifier(FPDF_DOCUMENT document, FPDF_FILEIDTYPE id_type, void* buffer, unsigned long buflen);.
 /// </remarks>
 public ulong FPDF_GetFileIdentifier(FPDF_DOCUMENT document, FPDF_FILEIDTYPE id_type, IntPtr buffer, ulong buflen)
 {
     lock (_syncObject)
     {
         return(FPDF_GetFileIdentifierStatic(document, id_type, buffer, buflen));
     }
 }
예제 #7
0
 /// <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));
     }
 }
예제 #8
0
 /// <summary>
 /// Get destination info for |link|.
 /// </summary>
 /// <param name="document">Handle to the document.</param>
 /// <param name="link">Handle to the link.</param>
 /// <returns>Returns a handle to the destination, or NULL if there is no destination associated with the link.
 /// In this case, you should call FPDFLink_GetAction() to retrieve the action associated with |link|.</returns>
 /// <remarks>
 /// FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFLink_GetDest(FPDF_DOCUMENT document, FPDF_LINK link);.
 /// </remarks>
 public FPDF_DEST FPDFLink_GetDest(FPDF_DOCUMENT document, FPDF_LINK link)
 {
     lock (_syncObject)
     {
         return(FPDFLink_GetDestStatic(document, link));
     }
 }
예제 #9
0
 /// <summary>
 /// Get the page index of |dest|.
 /// </summary>
 /// <param name="document">Handle to the document.</param>
 /// <param name="dest">Handle to the destination.</param>
 /// <returns>Returns the 0-based page index containing |dest|. Returns -1 on error.</returns>
 /// <remarks>
 /// FPDF_EXPORT int FPDF_CALLCONV FPDFDest_GetDestPageIndex(FPDF_DOCUMENT document, FPDF_DEST dest);.
 /// </remarks>
 public int FPDFDest_GetDestPageIndex(FPDF_DOCUMENT document, FPDF_DEST dest)
 {
     lock (_syncObject)
     {
         return(FPDFDest_GetDestPageIndexStatic(document, dest));
     }
 }
예제 #10
0
 /// <summary>
 /// Get the URI path of |action|.
 /// </summary>
 /// <param name="document">Handle to the document.</param>
 /// <param name="action">Handle to the action. Must be a |PDFACTION_URI|.</param>
 /// <param name="buffer">A buffer for the path string. 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 URI path, including the trailing NUL character, or 0 on error,
 /// typically because the arguments were bad or the action was of the wrong type.</returns>
 /// <remarks>
 /// The |buffer| is always encoded in 7-bit ASCII. If |buflen| is less than the returned length,
 /// or |buffer| is NULL, |buffer| will not be modified.
 /// FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFAction_GetURIPath(FPDF_DOCUMENT document, FPDF_ACTION action, void* buffer, unsigned long buflen);.
 /// </remarks>
 public int FPDFAction_GetURIPath(FPDF_DOCUMENT document, FPDF_ACTION action, IntPtr buffer, ulong buflen)
 {
     lock (_syncObject)
     {
         return(FPDFAction_GetURIPathStatic(document, action, buffer, buflen));
     }
 }
예제 #11
0
 /// <summary>
 /// Get the destination of |action|.
 /// </summary>
 /// <param name="document">Handle to the document.</param>
 /// <param name="action">Handle to the action. |action| must be a |PDFACTION_GOTO| or |PDFACTION_REMOTEGOTO|.</param>
 /// <returns>Returns a handle to the destination data, or NULL on error,
 /// typically because the arguments were bad or the action was of the wrong type.</returns>
 /// <remarks>
 /// In the case of |PDFACTION_REMOTEGOTO|, you must first call FPDFAction_GetFilePath(), then load the document at that path,
 /// then pass the document handle from that document as |document| to FPDFAction_GetDest().
 /// FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFAction_GetDest(FPDF_DOCUMENT document, FPDF_ACTION action);.
 /// </remarks>
 public FPDF_DEST FPDFAction_GetDest(FPDF_DOCUMENT document, FPDF_ACTION action)
 {
     lock (_syncObject)
     {
         return(FPDFAction_GetDestStatic(document, action));
     }
 }
예제 #12
0
 /// <summary>
 /// Find the bookmark with |title| in |document|.
 /// </summary>
 /// <param name="document">Handle to the document.</param>
 /// <param name="title">The UTF-16LE encoded Unicode title for which to search.</param>
 /// <returns>Returns the handle to the bookmark, or NULL if |title| can't be found.</returns>
 /// <remarks>
 /// FPDFBookmark_Find() will always return the first bookmark found even if multiple bookmarks have the same |title|.
 /// FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_WIDESTRING title);.
 /// </remarks>
 public FPDF_BOOKMARK FPDFBookmark_Find(FPDF_DOCUMENT document, IntPtr title)
 {
     lock (_syncObject)
     {
         return(FPDFBookmark_FindStatic(document, title));
     }
 }
예제 #13
0
 /// <summary>
 /// Returns a font object loaded from a stream of data. The font is loaded
 /// into the document. The caller does not need to free the returned object.
 /// </summary>
 /// <param name="document">Handle to the document.</param>
 /// <param name="cid">A value specifying if the font is a CID font or not.</param>
 /// <param name="data">The data, which will be copied by the font object.</param>
 /// <param name="index">The index of the first byte to be copied from <paramref name="data"/>.</param>
 /// <param name="count">The number of bytes to copy from <paramref name="data"/> or a negative value to copy all bytes.</param>
 /// <returns>Returns NULL on failure.</returns>
 public static FPDF_FONT FPDFText_LoadFont(FPDF_DOCUMENT document, FontTypes font_type, bool cid, byte[] data, int index = -1, int count = 0)
 {
     if (count < 0)
     {
         count = data.Length - index;
     }
     return(FPDFText_LoadFont(document, ref data[index], (uint)count, font_type, cid));
 }
예제 #14
0
        /// <summary>
        /// Imports pages from <paramref name="src_doc"/> to <paramref name="dest_doc"/>
        /// </summary>
        /// <param name="index">Zero-based index of where the imported pages should be inserted in the destination document.</param>
        /// <param name="srcPageIndices">Zero-based indices of the pages to import in the source document</param>
        public static bool FPDF_ImportPages(FPDF_DOCUMENT dest_doc, FPDF_DOCUMENT src_doc, int index, params int[] srcPageIndices)
        {
            string pageRange = null;

            if (srcPageIndices != null && srcPageIndices.Length > 0)
            {
                pageRange = string.Join(",", srcPageIndices.Select(p => (p + 1).ToString(CultureInfo.InvariantCulture)));
            }
            return(FPDF_ImportPages(dest_doc, src_doc, pageRange, index));
        }
예제 #15
0
        //public static string FPDF_VIEWERREF_GetName(FPDF_DOCUMENT document, string key)
        //{
        //	byte b = 0;
        //	uint length = FPDF_VIEWERREF_GetName(document, key, ref b, 0);
        //	if (length == 0)
        //		return null;
        //	var buffer = new byte[length];
        //	FPDF_VIEWERREF_GetName(document, key, ref buffer[0], length);
        //	return Encoding.UTF8.GetString(buffer);
        //}

        /// <summary>
        /// Get the named destination by index.
        /// </summary>
        /// <param name="document">Handle to a document.</param>
        /// <param name="index">The index of a named destination.</param>
        /// <returns>
        /// The destination handle and name for a given index, or (<see cref="FPDF_DEST.Null"/>, <c>null</c>)
        /// if there is no named destination corresponding to <paramref name="index"/>.
        /// </returns>
        /// <seealso cref="PdfDestinationCollection[int]"/>
        /// <seealso cref="PdfDocument.Destinations"/>
        public static (FPDF_DEST Destination, string Name) FPDF_GetNamedDest(FPDF_DOCUMENT document, int index)
        {
            FPDF_GetNamedDest(document, index, IntPtr.Zero, out int length);
            if (length < 1)
            {
                return(FPDF_DEST.Null, null);
            }
            var buffer = new byte[length];
            var dest   = FPDF_GetNamedDest(document, index, ref buffer[0], ref length);

            if (length < 1)
            {
                return(FPDF_DEST.Null, null);
            }
            return(dest, Encoding.Unicode.GetString(buffer, 0, (int)length - 2));
        }
예제 #16
0
        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);
            }
        }
예제 #17
0
        /// <summary>
        ///     Saves a PDF document to a stream.
        /// </summary>
        /// <param name="version">
        ///     The new PDF file version of the saved file.
        ///     14 for 1.4, 15 for 1.5, etc. Values smaller than 10 are ignored.
        /// </param>
        /// <seealso cref="PDFium.FPDF_SaveAsCopy(FPDF_DOCUMENT, FPDF_FILEWRITE, SaveFlags)" />
        /// <seealso cref="PDFium.FPDF_SaveWithVersion(FPDF_DOCUMENT, FPDF_FILEWRITE, SaveFlags, int)" />
        public static bool FPDF_SaveAsCopy(FPDF_DOCUMENT document, Stream stream, SaveFlags flags, int version = 0)
        {
            byte[] buffer    = null;
            var    fileWrite = new FPDF_FILEWRITE((ignore, data, size) =>
            {
                if (buffer == null || buffer.Length < size)
                {
                    buffer = new byte[size];
                }

                Marshal.Copy(data, buffer, 0, size);
                stream.Write(buffer, 0, size);
                return(true);
            });

            return(version >= 10 ? FPDF_SaveWithVersion(document, fileWrite, flags, version) : FPDF_SaveAsCopy(document, fileWrite, flags));
        }
예제 #18
0
        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);
            }
        }
예제 #19
0
 /// <summary>
 ///     Get meta-data <paramref name="tag" /> content from <paramref name="document" />.
 /// </summary>
 /// <param name="document">Handle to the document.</param>
 /// <param name="tag">The tag to retrieve.</param>
 /// <returns>The meta-data.</returns>
 /// <remarks>
 ///     For detailed explanations of these tags and their respective
 ///     values, please refer to PDF Reference 1.6, section 10.2.1,
 ///     'Document Information Dictionary'.
 /// </remarks>
 /// <seealso href="http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdf">PDF Reference</seealso>
 /// <seealso cref="PdfDocument.GetMetaText(MetadataTags)" />
 public static string FPDF_GetMetaText(FPDF_DOCUMENT document, MetadataTags tag) => FPDF_GetMetaText(document, tag.ToString());
예제 #20
0
 /// <summary>
 ///     Get meta-data <paramref name="tag" /> content from <paramref name="document" />.
 /// </summary>
 /// <param name="document">Handle to the document.</param>
 /// <param name="tag">
 ///     The tag to retrieve. The tag can be one of:
 ///     Title, Author, Subject, Keywords, Creator, Producer,
 ///     CreationDate, or ModDate.
 /// </param>
 /// <returns>The meta-data.</returns>
 /// <remarks>
 ///     For detailed explanations of these tags and their respective
 ///     values, please refer to PDF Reference 1.6, section 10.2.1,
 ///     'Document Information Dictionary'.
 /// </remarks>
 /// <seealso href="http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdf">PDF Reference</seealso>
 /// <seealso cref="PdfDocument.GetMetaText(MetadataTags)" />
 public static string FPDF_GetMetaText(FPDF_DOCUMENT document, string tag) => GetUtf16String((ref byte buffer, int length)
                                                                                             => (int)FPDF_GetMetaText(document, tag, ref buffer, (uint)length), sizeof(byte), true);
예제 #21
0
 /// <summary>
 ///     Gets URI path of a <see cref="FPDF_ACTION" /> of type <see cref="ActionTypes.Uri" />.
 /// </summary>
 /// <param name="document">Handle to the document.</param>
 /// <param name="action">Handle to the action. Must be of type <see cref="ActionTypes.Uri" />.</param>
 /// <returns>The URI path of <paramref name="action" />.</returns>
 /// <seealso cref="PdfAction.Uri" />
 public static string FPDFAction_GetURIPath(FPDF_DOCUMENT document, FPDF_ACTION action)
 => GetAsciiString((ref byte buffer, int length) => (int)FPDFAction_GetURIPath(document, action, ref buffer, (uint)length));
예제 #22
0
        public void FPDF_DOCUMENT_Constructor_Call2_Success()
        {
            var h = new FPDF_DOCUMENT(new IntPtr(1));

            Assert.IsTrue(h.IsValid);
        }
예제 #23
0
        public void FPDF_DOCUMENT_Constructor_Call1_Success()
        {
            var h = new FPDF_DOCUMENT();

            Assert.IsFalse(h.IsValid);
        }