Skip to content

Instantly share code, notes, and snippets.

@witwall
Last active August 29, 2015 14:03
Show Gist options
  • Save witwall/4070584b4694ca906cdc to your computer and use it in GitHub Desktop.
Save witwall/4070584b4694ca906cdc to your computer and use it in GitHub Desktop.
Converting PDF to Bitmap with the help of PDFium and EasyBMP
//for detail, please visit
//http://blog.rubypdf.com/2014/07/08/convert-pdf-to-bitmap-with-pdfium
//do not forget #include "EasyBMP.h" first
static void WriteBmp(const char* pdf_name, int num,
const char* buffer, int stride
, int width, int height) {
BMP bmp;
bmp.SetSize(width,height);
// Set its color depth to 32-bits
bmp.SetBitDepth(32);
// Set the pixels
for (int h = 0; h < height; ++h) {
const char* src_line = buffer + (stride * h);
for (int w = 0; w < width; ++w) {
bmp(w,h)->Red = src_line[(w * 4) + 2];
bmp(w,h)->Green = src_line[(w * 4) + 1];
bmp(w,h)->Blue = src_line[w * 4];
bmp(w,h)->Alpha = 0;
}
}
char filename[256];
snprintf(filename, sizeof(filename), "%s.%d.bmp", pdf_name, num);
bmp.WriteToFile(filename);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment