Exemple #1
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);
        }
        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);
            }
        }