コード例 #1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                StreamManager.Unregister(_id);

                if (_form != IntPtr.Zero)
                {
                    NativeMethods.FORM_DoDocumentAAction(_form, NativeMethods.FPDFDOC_AACTION.WC);
                    NativeMethods.FPDFDOC_ExitFormFillEnvironment(_form);
                    _form = IntPtr.Zero;
                }

                if (_document != IntPtr.Zero)
                {
                    NativeMethods.FPDF_CloseDocument(_document);
                    _document = IntPtr.Zero;
                }

                if (_formCallbacksHandle.IsAllocated)
                {
                    _formCallbacksHandle.Free();
                }

                if (_stream != null)
                {
                    _stream.Dispose();
                    _stream = null;
                }

                _disposed = true;
            }
        }
コード例 #2
0
        private static int FPDF_SaveBlock(IntPtr fileWrite, IntPtr data, uint size)
        {
            var write = new FPDF_FILEWRITE();

            Marshal.PtrToStructure(fileWrite, write);

            var stream = StreamManager.Get((int)write.stream);

            if (stream == null)
            {
                return(0);
            }

            byte[] buffer = new byte[size];
            Marshal.Copy(data, buffer, 0, (int)size);

            try
            {
                stream.Write(buffer, 0, (int)size);
                return((int)size);
            }
            catch
            {
                return(0);
            }
        }
コード例 #3
0
        public PdfFile(Stream stream, string password)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            PdfLibrary.EnsureLoaded();

            _stream = stream;
            _id     = StreamManager.Register(stream);

            var document = NativeMethods.FPDF_LoadCustomDocument(stream, password, _id);

            if (document == IntPtr.Zero)
            {
                throw new PdfException((PdfError)NativeMethods.FPDF_GetLastError());
            }

            LoadDocument(document);
        }
コード例 #4
0
        private static int FPDF_GetBlock(IntPtr param, uint position, IntPtr buffer, uint size)
        {
            var stream = StreamManager.Get((int)param);

            if (stream == null)
            {
                return(0);
            }
            byte[] managedBuffer = new byte[size];

            stream.Position = position;
            int read = stream.Read(managedBuffer, 0, (int)size);

            if (read != size)
            {
                return(0);
            }

            Marshal.Copy(managedBuffer, 0, buffer, (int)size);
            return(1);
        }
コード例 #5
0
        public static bool FPDF_SaveWithVersion(IntPtr doc, Stream output, FPDF_SAVE_FLAGS flags, int fileVersion)
        {
            int id = StreamManager.Register(output);

            try
            {
                var write = new FPDF_FILEWRITE
                {
                    stream     = (IntPtr)id,
                    version    = 1,
                    WriteBlock = Marshal.GetFunctionPointerForDelegate(_saveBlockDelegate)
                };

                lock (LockString)
                {
                    return(Imports.FPDF_SaveWithVersion(doc, write, flags, fileVersion));
                }
            }
            finally
            {
                StreamManager.Unregister(id);
            }
        }