internal static async Task <PdfPage> Create( ThreadDispatcher dispatcher, FpdfDocumentT documentInstance, int pageIndex) { var loadPageResult = await dispatcher.QueueWithResult(() => fpdfview.FPDF_LoadPage(documentInstance, pageIndex)); if (loadPageResult == null) { throw new Exception($"Failed to open page for page index {pageIndex}."); } var page = new PdfPage(dispatcher, documentInstance, loadPageResult) { InitialIndex = pageIndex }; var getPageSizeResult = await dispatcher.QueueWithResult(() => { var size = new FS_SIZEF_(); var result = fpdfview.FPDF_GetPageSizeByIndexF(documentInstance, pageIndex, size); return(result == 0 ? null : size); }); if (getPageSizeResult == null) { throw new Exception($"Could not retrieve page size for page index {pageIndex}."); } page.Size = new SizeF(getPageSizeResult.Width, getPageSizeResult.Height); return(page); }
public DocumentWrapper(FpdfDocumentT instance) { Instance = instance; if (Instance == null) { throw new DocnetException("unable to open the document"); } }
public DocumentWrapper(string filePath, string password) { Instance = fpdf_view.FPDF_LoadDocument(filePath, password); if (Instance == null) { throw new DocnetException("unable to open the document"); } }
public void Dispose() { if (Instance == null) { return; } fpdf_view.FPDF_CloseDocument(Instance); Instance = null; }
public void Dispose() { if (Instance == null) { return; } fpdf_view.FPDF_CloseDocument(Instance); Marshal.FreeHGlobal(_ptr); Instance = null; }
public DocumentWrapper(byte[] bytes, string password) { _ptr = Marshal.AllocHGlobal(bytes.Length); Marshal.Copy(bytes, 0, _ptr, bytes.Length); Instance = fpdf_view.FPDF_LoadMemDocument(_ptr, bytes.Length, password); if (Instance == null) { throw new DocnetLoadDocumentException("unable to open the document", fpdf_view.FPDF_GetLastError()); } }
public static bool FPDF_SaveAsCopy(FpdfDocumentT document, Stream stream) { byte[] buffer = null; var fileWrite = new FpdfStreamWriter((writerPtr, 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); }); var result = FPDF_SaveAsCopy(document.__Instance, fileWrite, 3); GC.KeepAlive(fileWrite); return(result == 1); }
private PdfDocument(PDFiumCoreManager manager, FpdfDocumentT documentInstance) { _manager = manager; _documentInstance = documentInstance; }
private PdfPage(ThreadDispatcher dispatcher, FpdfDocumentT documentInstance, FpdfPageT pageInstance) { _dispatcher = dispatcher; _documentInstance = documentInstance; _pageInstance = pageInstance; }