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); }
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); } }