Esempio n. 1
0
        }         // func Open

        /// <summary>Open the file from an stream.</summary>
        /// <param name="data">Data stream (the must seek- and readable).</param>
        /// <param name="name">Name of the pdf.</param>
        /// <param name="password">Password of the pdf</param>
        /// <returns>Pdf document reader</returns>
        public static PdfReader Open(Stream data, string name = null, SecureString password = null)
        {
            var documentAccess = new PdfDocumentAccess(data);
            var fileAccess     = new FPDF_FILEACCESS()
            {
                getBlock  = documentAccess.GetBlockDelegateObject,
                m_FileLen = (uint)documentAccess.FileLength,
                param     = IntPtr.Zero
            };

            if (String.IsNullOrEmpty(name))
            {
                if (data is FileStream fs)
                {
                    name = fs.Name;
                }
                else
                {
                    name = "stream.pdf";
                }
            }

            lock (FPDF_LibraryLock)
            {
                var documentHandle = new PdfDocumentHandle(FPDF_LoadCustomDocument(ref fileAccess, IntPtr.Zero));
                if (documentHandle.IsInvalid)
                {
                    throw PdfReaderException.Create(name);
                }

                return(new PdfReader(documentHandle, name, documentAccess));
            }
        }         // func Open
        /// <summary>
        /// Opens a document using a .NET Stream. Allows opening huge
        /// PDFs without loading them into memory first.
        /// </summary>
        /// <param name="input">The input Stream. Don't dispose prior to closing the pdf.</param>
        /// <param name="password">Password, if the PDF is protected. Can be null.</param>
        /// <param name="id">Retrieves an IntPtr to the COM object for the Stream. The caller must release this with Marshal.Release prior to Disposing the Stream.</param>
        /// <returns>An IntPtr to the FPDF_DOCUMENT object.</returns>
        public static IntPtr FPDF_LoadCustomDocument(Stream input, string password, int id)
        {
            var getBlock = Marshal.GetFunctionPointerForDelegate(_getBlockDelegate);

            var access = new FPDF_FILEACCESS
            {
                m_FileLen  = (uint)input.Length,
                m_GetBlock = getBlock,
                m_Param    = (IntPtr)id
            };

            lock (LockString)
            {
                return(Imports.FPDF_LoadCustomDocument(access, password));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Opens a document using a .NET Stream. Allows opening huge
        /// PDFs without loading them into memory first.
        /// </summary>
        /// <param name="input">The input Stream. Don't dispose prior to closing the pdf.</param>
        /// <param name="password">Password, if the PDF is protected. Can be null.</param>
        /// <param name="streamPtr">Retrieves an IntPtr to the COM object for the Stream. The caller must release this with Marshal.Release prior to Disposing the Stream.</param>
        /// <returns>An IntPtr to the FPDF_DOCUMENT object.</returns>
        public static IntPtr FPDF_LoadCustomDocument(Stream input, string password, out IntPtr streamPtr)
        {
            streamPtr = Marshal.GetIUnknownForObject(input);

            IntPtr getBlock = Marshal.GetFunctionPointerForDelegate(_getBlockDelegate);
            IntPtr result;

            FPDF_FILEACCESS access = new FPDF_FILEACCESS
            {
                m_FileLen  = (uint)input.Length,
                m_GetBlock = getBlock,
                m_Param    = streamPtr
            };

            lock (LockString)
            {
                result = Imports.FPDF_LoadCustomDocument(access, password);
            }

            return(result);
        }
 public static extern IntPtr FPDF_LoadCustomDocument([MarshalAs(UnmanagedType.LPStruct)] FPDF_FILEACCESS access, string password);
Esempio n. 5
0
 public static extern IntPtr FPDF_LoadCustomDocument([In] ref FPDF_FILEACCESS pFileAccess, [In] IntPtr password);
        /// <summary>
        /// Opens a document using a .NET Stream. Allows opening huge
        /// PDFs without loading them into memory first.
        /// </summary>
        /// <param name="input">The input Stream. Don't dispose prior to closing the pdf.</param>
        /// <param name="password">Password, if the PDF is protected. Can be null.</param>
        /// <param name="streamPtr">Retrieves an IntPtr to the COM object for the Stream. The caller must release this with Marshal.Release prior to Disposing the Stream.</param>
        /// <returns>An IntPtr to the FPDF_DOCUMENT object.</returns>
        public static IntPtr FPDF_LoadCustomDocument(Stream input, string password, int id)
        {
            var getBlock = Marshal.GetFunctionPointerForDelegate(_getBlockDelegate);

            var access = new FPDF_FILEACCESS
            {
                m_FileLen = (uint)input.Length,
                m_GetBlock = getBlock,
                m_Param = (IntPtr)id
            };

            lock (LockString)
            {
                return Imports.FPDF_LoadCustomDocument(access, password);
            }
        }