Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert image data (PDEImage) in PDF to DIB using C++?
    text
    copied!<p>I am trying to extract all the images in a PDF and then convert them into DIB format. First part is easy. I extract all the contents in the PDF, then iterate through them and whenever I find a PDEImage, I put them in an array.</p> <p>But I am clueless about how to go about the second part. Looks like all the AVConversion methods allow you to convert a whole page of a PDF, not just images, into other formats.</p> <p>Is there any way I can accomplish this task? Thanks in advance!</p> <p><strong>EDIT: Further elaborating the problem.</strong></p> <p>I am writing an Adobe Acrobat Plug-in using Visual C++ with .NET Framework 4.</p> <p>The purpose of the plug-in is to (among other things) extract image data from a PDF file, then convert those data to DIBs. The need to convert to DISs is because I then pass those DIBs to another library which do some image correction work on them.</p> <p>Now my problem is with converting the said image data in PDFs to DIBs. The image data on PDFs are found in a format called PDEImage (Ref Link) where apparently it contains all the color data of the image. Now I'm using the following code to extract the said image data bits from the image to be used with CreateCompatibleBitmap() and SetBitmapBits() to obtain a HBITMAP handle. Then, I pass that along with other necessary parameters to the GetDIBits() to obtain a DIB in the form of a byte array as stated in the MSDN.</p> <pre><code>void GetDIBImage(PDEElement element) { //Obtaining a PDEImage PDEImage image; memset(&amp;image, 0, sizeof(PDEImage)); image = (PDEImage)element; //Obtaining attributes (such as width, height) //of the image for later use PDEImageAttrs attrs; memset(&amp;attrs, 0, sizeof(attrs)); PDEImageGetAttrs(image, &amp;attrs, sizeof(attrs)); //Obtainig image data from PDEImage to a byte array ASInt32 len = PDEImageGetDataLen(image); byte *data = (byte *)malloc(len); PDEImageGetData(image, 0, data); //Creating a DDB using said data HDC hdc = CreateCompatibleDC(NULL); HBITMAP hBmp = CreateCompatibleBitmap(hdc, attrs.width, attrs.height); LONG bitsSet = SetBitmapBits(hBmp, len, data); //Here bitsSet gets a value of 59000 which is close to the image's actual size //Buffer which GetDIBits() will fill with DIB data unsigned char* buff = new unsigned char[len]; //BITMAPINFO stucture to be passed to GetDIBits() BITMAPINFO bmpInfo; memset(&amp;bmpInfo, 0, sizeof(bmpInfo)); bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmpInfo.bmiHeader.biWidth = (LONG)attrs.width; bmpInfo.bmiHeader.biHeight = (LONG)attrs.height; bmpInfo.bmiHeader.biPlanes = 1; bmpInfo.bmiHeader.biBitCount = 8; bmpInfo.bmiHeader.biCompression = BI_RGB; bmpInfo.bmiHeader.biSizeImage = ((((bmpInfo.bmiHeader.biWidth * bmpInfo.bmiHeader.biBitCount) + 31) &amp; ~31) &gt;&gt; 3) * bmpInfo.bmiHeader.biHeight; bmpInfo.bmiHeader.biXPelsPerMeter = 0; bmpInfo.bmiHeader.biYPelsPerMeter = 0; bmpInfo.bmiHeader.biClrUsed = 0; bmpInfo.bmiHeader.biClrImportant = 0; //Callling GetDIBits() //Here scanLines get a value of 0, while buff receives no data. int scanLines = GetDIBits(hdc, hBmp, 0, attrs.height, &amp;buff, &amp;bmpInfo, DIB_RGB_COLORS); if(scanLines &gt; 0) { MessageBox(NULL, L"SUCCESS", L"Message", MB_OK); } else { MessageBox(NULL, L"FAIL", L"Message", MB_OK); } } </code></pre> <p>Here are my questions / concerns.</p> <ol> <li><p>Is it correct the way I'm using CreateCompatibleDC(), CreateCompatibleBitmap() and SetBitmapBits() functions? My thinking is that I use CreateCompatibleDC() to obtain current DC, then create a DDB using CreateCompatibleBitmap() and then set the actual data to the DDB using SetBitmapBits(). Is that correct?</p></li> <li><p>Is there a problem with the way I've created the BITMAPINFO structure. I am under the assumption that it need to contain all the details regarding the format of the DIB I will eventually obtain.</p></li> <li><p>Why am I not getting the bitmap data as a DIB to the buff when I call GetDIBits()?</p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload