public static void CloseContext(IntPtr ctx) { if (!Inited) { return; } MuPDFLib.CloseContext(ctx); }
public static void Deinit() { if (Inited) { MuPDFLib.Deinit(); context = IntPtr.Zero; Inited = false; } ; }
public void Dispose() { if (Handle != IntPtr.Zero) { lock (staticLock) MuPDFLib.CloseDocument(Handle); Handle = IntPtr.Zero; Disposed = true; } }
private void CreateWrapper() { var handle = IntPtr.Zero; if (File.Exists(FilePath)) { // utf8 string with terminating zero lock (staticLock) handle = MuPDFLib.LoadDocument(Encoding.UTF8.GetBytes(FilePath + "\0")); } wrapper = new PDFDocumentWrapper(handle); }
public CGSize GetPageSize(int pdfPage) { float width = 0, height = 0; lock (staticLock) { IntPtr page = MuPDFLib.LoadPage(context, Handle, pdfPage); try { MuPDFLib.GetPageSize(Handle, page, out width, out height); return(new CGSize((int)Math.Ceiling(width), (int)Math.Ceiling(height))); } finally { MuPDFLib.ClosePage(context, Handle, page); } } }
public static void Init() { if (!Inited) { try { // 128MB UInt32 storeSize = 128 << 20; MuPDFLib.Init(storeSize); context = MuPDFLib.GetContext(); Inited = true; Console.WriteLine("MuPDFLib Store size: " + storeSize); } catch (DllNotFoundException) { Console.WriteLine("dll not found!"); } catch (EntryPointNotFoundException ex) { Console.WriteLine(ex); } } }
public NativeBitmap RenderToBitmap(IntPtr ctx, CGRect bbox, double K, int pdfPage, int angle, ref MuPDFLib.Cookie cookie) { lock (this) { NativeBitmap nbmp = null; IntPtr PDFPage = MuPDFLib.LoadPage(ctx, Handle, pdfPage); try { nbmp = new NativeBitmap((int)bbox.Width, (int)bbox.Height, 32); MuPDFLib.RenderPageToBytes(ctx, Handle, PDFPage, nbmp.bits, (int)bbox.X, (int)bbox.Y, (int)bbox.Width, (int)bbox.Height, (float)K, angle / 90, ref cookie); if (cookie.abort != 0) { nbmp.Dispose(); nbmp = null; } } finally { MuPDFLib.ClosePage(ctx, Handle, PDFPage); } return(nbmp); } }