private static int FPDF_SaveBlock(IntPtr fileWrite, IntPtr data, uint size) { FPDF_FILEWRITE write = new FPDF_FILEWRITE(); Marshal.PtrToStructure(fileWrite, write); Stream stream = Marshal.GetObjectForIUnknown(write.stream) as 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); } }
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); } }
/// <summary> /// Saves a PDF document to a stream. /// </summary> /// <param name="version"> /// The new PDF file version of the saved file. /// 14 for 1.4, 15 for 1.5, etc. Values smaller than 10 are ignored. /// </param> /// <seealso cref="PDFium.FPDF_SaveAsCopy(FPDF_DOCUMENT, FPDF_FILEWRITE, SaveFlags)" /> /// <seealso cref="PDFium.FPDF_SaveWithVersion(FPDF_DOCUMENT, FPDF_FILEWRITE, SaveFlags, int)" /> public static bool FPDF_SaveAsCopy(FPDF_DOCUMENT document, Stream stream, SaveFlags flags, int version = 0) { byte[] buffer = null; var fileWrite = new FPDF_FILEWRITE((ignore, data, size) => { if (buffer == null || buffer.Length < size) { buffer = new byte[size]; } Marshal.Copy(data, buffer, 0, size); stream.Write(buffer, 0, size); return(true); }); return(version >= 10 ? FPDF_SaveWithVersion(document, fileWrite, flags, version) : FPDF_SaveAsCopy(document, fileWrite, flags)); }
public static bool FPDF_SaveWithVersion(IntPtr doc, Stream output, FPDF_SAVE_FLAGS flags, int fileVersion) { IntPtr streamPtr = Marshal.GetIUnknownForObject(output); FPDF_FILEWRITE write = new FPDF_FILEWRITE { stream = streamPtr, version = 1, WriteBlock = Marshal.GetFunctionPointerForDelegate(_saveBlockDelegate) }; bool result = false; lock (LockString) { result = Imports.FPDF_SaveWithVersion(doc, write, flags, fileVersion); } Marshal.Release(streamPtr); output.Flush(); return(result); }
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); } }
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); } }
public static extern bool FPDF_SaveWithVersion(IntPtr doc, [MarshalAs(UnmanagedType.LPStruct)] FPDF_FILEWRITE writer, [MarshalAs(UnmanagedType.I4)] FPDF_SAVE_FLAGS flags, int fileVersion);
public static extern bool FPDF_SaveAsCopy(IntPtr doc, [MarshalAs(UnmanagedType.LPStruct)] FPDF_FILEWRITE writer, [MarshalAs(UnmanagedType.I4)] FPDF_SAVE_FLAGS flag);
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; } }
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); } }