Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public DocumentWrapper(FpdfDocumentT instance)
        {
            Instance = instance;

            if (Instance == null)
            {
                throw new DocnetException("unable to open the document");
            }
        }
Esempio n. 3
0
        public DocumentWrapper(string filePath, string password)
        {
            Instance = fpdf_view.FPDF_LoadDocument(filePath, password);

            if (Instance == null)
            {
                throw new DocnetException("unable to open the document");
            }
        }
Esempio n. 4
0
        public void Dispose()
        {
            if (Instance == null)
            {
                return;
            }

            fpdf_view.FPDF_CloseDocument(Instance);

            Instance = null;
        }
Esempio n. 5
0
        public void Dispose()
        {
            if (Instance == null)
            {
                return;
            }

            fpdf_view.FPDF_CloseDocument(Instance);

            Marshal.FreeHGlobal(_ptr);

            Instance = null;
        }
Esempio n. 6
0
        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());
            }
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
 private PdfDocument(PDFiumCoreManager manager, FpdfDocumentT documentInstance)
 {
     _manager          = manager;
     _documentInstance = documentInstance;
 }
Esempio n. 9
0
 private PdfPage(ThreadDispatcher dispatcher, FpdfDocumentT documentInstance, FpdfPageT pageInstance)
 {
     _dispatcher       = dispatcher;
     _documentInstance = documentInstance;
     _pageInstance     = pageInstance;
 }