예제 #1
0
        private static int FPDF_SaveBlock(IntPtr fileWrite, IntPtr data, uint size)
        {
            var write = new FPDF_FILEWRITE();

            Marshal.PtrToStructure(fileWrite, write);

            var stream = StreamDictionary.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);
            }
        }
예제 #2
0
        protected void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            StreamDictionary.Remove(_streamId);

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

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

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

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

            _disposed = true;
        }
예제 #3
0
        public PdfObject(Stream pdfStream, string password)
        {
            if (pdfStream == null)
            {
                throw new ArgumentNullException(nameof(pdfStream));
            }

            PdfiumLibrary.Init();

            _stream   = pdfStream;
            _streamId = StreamDictionary.Add(pdfStream);

            var document = PdfiumLibrary.FPDF_LoadCustomDocument(pdfStream, password, _streamId);

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

            LoadDocument(document);
        }
예제 #4
0
        private static int FPDF_GetBlock(IntPtr id, uint position, IntPtr buffer, uint size)
        {
            var stream = StreamDictionary.Get((int)id);

            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_SaveAsCopy(IntPtr doc, Stream output, FPDF_SAVE_FLAGS flags)
        {
            int id = StreamDictionary.Add(output);

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

                lock (_mutex)
                {
                    return(API.FPDF_SaveAsCopy(doc, write, flags));
                }
            }
            finally
            {
                StreamDictionary.Remove(id);
            }
        }