예제 #1
0
        protected byte[] GetPagePixelsInternal(byte[] buffer, int pageIndex, int width, int height, float dpiX, float dpiY, bool forPrinting)
        {
            IntPtr bitmapHandle;

            bitmapHandle = PdfiumDLL.FPDFBitmap_CreateEx(width, height, 4, buffer, width * 4);
            PdfiumDLL.FPDFBitmap_FillRect(bitmapHandle, 0, 0, width, height, new FPDFColor(0xFFFFFFFF));

            IntPtr pageHandle = PdfiumDLL.FPDF_LoadPage(documentHandle, pageIndex);

            PdfiumDLL.FPDF_RenderPageBitmap(bitmapHandle, pageHandle, 0, 0, width, height, 0, 0);
            PdfiumDLL.FPDF_ClosePage(pageHandle);

            PdfiumDLL.FPDFBitmap_Destroy(bitmapHandle);

            return(buffer);
        }
예제 #2
0
        public Bitmap GetPageImage(int pageIndex, int width, int height, float dpiX, float dpiY, bool forPrinting)
        {
            var        bitmap     = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
            BitmapData bitmapData = bitmap.LockBits(
                new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
            IntPtr bitmapHandle = PdfiumDLL.FPDFBitmap_CreateEx(width, height, 4, bitmapData.Scan0, width * 4);

            PdfiumDLL.FPDFBitmap_FillRect(bitmapHandle, 0, 0, width, height, new FPDFColor(0xFFFFFFFF));

            IntPtr pageHandle = PdfiumDLL.FPDF_LoadPage(documentHandle, pageIndex);

            PdfiumDLL.FPDF_RenderPageBitmap(bitmapHandle, pageHandle, 0, 0, width, height, 0, 0);
            PdfiumDLL.FPDF_ClosePage(pageHandle);

            bitmap.UnlockBits(bitmapData);
            PdfiumDLL.FPDFBitmap_Destroy(bitmapHandle);

            return(bitmap);
        }