FPDF_BITMAP EmbedderTest::RenderPage(FPDF_PAGE page) { int width = static_cast<int>(FPDF_GetPageWidth(page)); int height = static_cast<int>(FPDF_GetPageHeight(page)); FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, 0); FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF); FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0); return bitmap; }
FPDF_BITMAP EmbedderTest::RenderPage(FPDF_PAGE page) { int width = static_cast<int>(FPDF_GetPageWidth(page)); int height = static_cast<int>(FPDF_GetPageHeight(page)); int alpha = FPDFPage_HasTransparency(page) ? 1 : 0; FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, alpha); FPDF_DWORD fill_color = alpha ? 0x00000000 : 0xFFFFFFFF; FPDFBitmap_FillRect(bitmap, 0, 0, width, height, fill_color); FPDF_RenderPageBitmap(bitmap, page, 0, 0, width, height, 0, 0); FPDF_FFLDraw(form_handle_, bitmap, page, 0, 0, width, height, 0, 0); return bitmap; }
wxBitmap wxPDFViewPage::CreateBitmap(FPDF_PAGE page, FPDF_FORMHANDLE form, const wxSize& bmpSize, int flags) { FPDF_BITMAP bitmap = FPDFBitmap_Create(bmpSize.x, bmpSize.y, 0); FPDFBitmap_FillRect(bitmap, 0, 0, bmpSize.x, bmpSize.y, 0xFFFFFFFF); FPDF_RenderPageBitmap(bitmap, page, 0, 0, bmpSize.x, bmpSize.y, 0, flags); unsigned char* buffer = reinterpret_cast<unsigned char*>(FPDFBitmap_GetBuffer(bitmap)); if (form) FPDF_FFLDraw(form, bitmap, page, 0, 0, bmpSize.x, bmpSize.y, 0, flags); // Convert BGRA image data from PDF SDK to RGB image data wxBitmap bmp(bmpSize, 24); unsigned char* srcP = buffer; wxNativePixelData data(bmp); wxNativePixelData::Iterator p(data); for (int y = 0; y < bmpSize.y; ++y) { wxNativePixelData::Iterator rowStart = p; for (int x = 0; x < bmpSize.x; ++x, ++p) { p.Blue() = *(srcP++); p.Green() = *(srcP++); p.Red() = *(srcP++); srcP++; } p = rowStart; p.OffsetY(data, 1); } FPDFBitmap_Destroy(bitmap); return bmp; }