PDFToImageDrawToHDC2 function

Our gold support receipt number is XXXXXXXXX,

I have been trying to make the PDFToImageDrawToHDC2 function work on the pdf2image com sdk but I am having some problems....

BOOL __stdcall PDFToImageDrawToHDC2(LPBYTE lpPDFData, int nPDFDataLen, HDC hDC,
int nXDest, int nYDest, int nWidth, int nHeight,
const char *szUserPassword, const char *szOwnPassword, int xRes, int yRes,
int nBitCount, BOOL bGrayscale, int nPageIndex);

1. No matter what value I use for nBitCount or bGrayScale, I always get a bi-tonal image (rather than 8 or 24 bit for example).
2. I don't understand the relationship between dpi, nWidth and nHeight. Can I set nWidth and nHeight to 0 or -1?
3. How can I work out the size of the image before I call the function?

I kind of assumed that this function would be the same as PDFToImageDrawToHDC - except that it takes a LPBYTE rather than a file path as input, but it seems to be quite different.

Any suggestions to get it working?
====================================
>>1. No matter what value I use for nBitCount or bGrayScale, I always get a bi-tonal image (rather than 8 or 24 bit for example).

Please refer to following parameter pairs,

nBitCount=1, bGrayScale is ignored, you will get bi-tonal image (black and white image),
nBitCount=8, bGrayScale=FALSE, you will get a 8bit color image,
nBitCount=8, bGrayScale=TRUE, you will get a 8bit grayscale image,
nBitCount=24, bGrayScale is ignored, you will get a 24bit true color image,

if pdf2image SDK folder contains p2isdk.dll file, you can rename p2isdk.dll file to p2isdk.dll.old filename to try again.

>>2. I don't understand the relationship between dpi, nWidth and nHeight. Can I set nWidth and nHeight to 0 or -1?

If you wish display the PDF page to hDC, you need set valid parameters to "int nXDest, int nYDest, int nWidth, int nHeight", please refer to these parameters' definition at below,

Parameters

nXDest: Specifies the logical x-coordinate of the upper-left corner of the destination rectangle.

nYDest: Specifies the logical y-coordinate of the upper-left corner of the destination rectangle.

nWidth: Specifies the width (in logical units) of the destination rectangle and source bitmap.

nHeight: Specifies the height (in logical units) of the destination rectangle and source bitmap.

In one word, "int nXDest, int nYDest, int nWidth, int nHeight" parameters are used to draw the image to target HDC or screen, " int xRes, int yRes " parameters are used to render the PDF page to image, you can set xRes and yRes to 72, 150 or 300 DPI, then PDFToImageDrawToHDC2() function will render your PDF page to image at 72, 150 or 300 DPI, after that, PDFToImageDrawToHDC2() function will draw image to screen at a rectangle which defined by "int nXDest, int nYDest, int nWidth, int nHeight" parameters.

>>3. How can I work out the size of the image before I call the function?

Yes, this can be done easily, you can use following sample source code to get the PDF page count and page size of each PDF page,

--------------------------------------------------------------------
int pagecount = PDFToImageGetPageCount(szPDFFileName);
printf("Filename is: %s\n",szPDFFileName);
printf("Page count is: %d\n",pagecount);
{
for(int page = 1; page <= pagecount; page++)
{
double m_fPageBox[4];
PDFToImageGetPageBox(szPDFFileName,page,m_fPageBox);
printf("Page %3d box is: [%f,%f,%f,%f]\n",page,m_fPageBox[0],m_fPageBox[1],m_fPageBox[2],m_fPageBox[3]);
int nPageWidth = PDFToImageGetPageWidth(szPDFFileName,page);
int nPageHeight = PDFToImageGetPageHeight(szPDFFileName,page);

if(0)
{
_splitpath(szOutputName, drive, dir, fname, ext );
char fname2[MAX_PATH];
sprintf(fname2,"%s%04d",fname,page);
char path_buffer[MAX_PATH];
_makepath(path_buffer,drive, dir,fname2,ext);
nResult = PDFToImageConverterEx(szPDFFileName,path_buffer,NULL,NULL,1,
1018,1590,24,COMPRESSION_PACKBITS,70,TRUE,TRUE,page,page);
}
}
}
--------------------------------------------------------------------

You can call PDFToImageGetPageBox() or PDFToImageGetPageWidth() or PDFToImageGetPageHeight() functions from your source code to read paper size from PDF file easily.

>>I kind of assumed that this function would be the same as PDFToImageDrawToHDC - except that it takes a LPBYTE rather than a file path as input, but it seems to be quite different.
>>Any suggestions to get it working?

No, PDFToImageDrawToHDC() and PDFToImageDrawToHDC2() are use two different technologies to render the PDF page.

PDFToImageDrawToHDC() function is based on PDFToImageConverter() function,
PDFToImageDrawToHDC2() function is based on PDFToImageConverter2() function,

PDFToImageConverter() and PDFToImageConverter2() functions are using two different render engine, in general, you can use PDFToImageConverter2() to render your PDF page to image file, PDFToImageConverter2() is work better.

VeryPDF
====================================

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)

Related Posts

This entry was posted in PDF to Image Converter and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


Verify Code   If you cannot see the CheckCode image,please refresh the page again!