Foxit PDF SDK 5.3

How to extract the highest solution of an image in a pdf file using Foxit PDF SDK?

The real size of an image object is inside the dictionary of the pdf file, get the image object and then get the dictionary data for the image object.

Here is a simple example:

FSCRT_PAGE page = NULL;

ret = LoadPage(doc, i, &page);

if (FSCRT_ERRCODE_SUCCESS != ret){

printf("Failed to load a given page.n");

return ret;

}

FSPDF_PAGEOBJECTS pageObjs=NULL;

ret = FSPDF_Page_GetPageObjects(page, &pageObjs);

if (FSCRT_ERRCODE_SUCCESS != ret){

printf("Failed to get page objects.n");

return ret;

}

FS_INT32 imageCount = 0;

ret = FSPDF_PageObjects_CountObjects(page, pageObjs, FSPDF_PAGEOBJECT_IMAGE, &imageCount);

if (FSCRT_ERRCODE_SUCCESS != ret){

printf("Failed to get the number of image objects.n");

return ret;

}

for(int j=0; j<imageCount; j++){

FSPDF_PAGEOBJECT pageObj = NULL;

ret = FSPDF_PageObjects_GetObject(page, pageObjs, FSPDF_PAGEOBJECT_IMAGE, j, &pageObj);

if (FSCRT_ERRCODE_SUCCESS != ret){

printf("Failed to get an image object.n");

return ret;

}

FSPDF_OBJECT objStream = NULL; 

FSPDF_ImageObject_GetStream(page, pageObj, &objStream); 

FSPDF_OBJECT imageDict = NULL; 

FSPDF_Stream_GetDict(doc, objStream, &imageDict); 

FSCRT_BSTR keyHeight; keyHeight.str = "Height"; 

keyHeight.len = strlen(keyHeight.str); 

FS_INT32 nNumber = 0; 

FSPDF_Dictionary_GetInteger(doc, imageDict, &keyHeight, &nNumber); 

FSCRT_BSTR keyWidth; keyWidth.str = "Width"; 

keyWidth.len = strlen(keyWidth.str); 

FS_INT32 nNumber2 = 0; 

FSPDF_Dictionary_GetInteger(doc, imageDict, &keyWidth, &nNumber2); 

}

Note: Render the image based on the height and width to get the original image to get the highest quality.

For example: ret = FSCRT_Bitmap_Create((FS_INT32)width, (FS_INT32)height, FSCRT_BITMAPFORMAT_24BPP_RGB, NULL, 0, &m_bitmap);

Load Pages is used in the above code.  

FS_RESULT LoadPage(FSCRT_DOCUMENT doc, FS_INT32 index, FSCRT_PAGE *page )

{

FS_RESULT ret =  FSPDF_Doc_GetPage(doc, index, page);

if(FSCRT_ERRCODE_SUCCESS != ret)

{

printf("Failed to get the page %d\n", index+1);

return ret;

}

FSCRT_PROGRESS progress;

ret = FSPDF_Page_StartParse(*page, FSPDF_PAGEPARSEFLAG_NORMAL, &progress);

if (FSCRT_ERRCODE_SUCCESS != ret)

{

printf("Failed to parse pages.\n");

return ret;

}

//Continue to parse page, without pausing.

ret = FSCRT_Progress_Continue(progress, NULL);

if (FSCRT_ERRCODE_FINISHED != ret)

{

printf("Failed to finish parsing progress! \n", ret);

} else {

ret = FSCRT_ERRCODE_SUCCESS;

printf("Succeed to Parse a given PDF page! \n");

}

FSCRT_Progress_Release(progress);

return ret;

}

Note: This article refers to a deprecated version of a Foxit Product. If you are still using Foxit PDF SDK 5.3 or older, please refer to your download package documents for Developer Guide and API Reference.

Get a trial version of the new Foxit PDF SDK and see our latest generation SDK’s brand new features!

Updated on April 4, 2017

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: