I am using the LeadTools version 14.5 with pdf support. The code I am about to display works but the conversion of each pdf page seems slower than it should. I thought I could remedy it by passing the FILEINFO struct to the L_LoadBitmap function but when I do that it doesn't seem to be using the correct information. Can anyone shed some light on this situation? I need to know why when I pass my fileInfo var into the L_LoadBitmap it doesn't work even if I modify the fileInfos page # each time I change the loadfileoptions page #.
Also, I would like to store the bitmap into memory for use with multi-threading to convert large pdf files multiple pages at a time. Would this be thread safe if I called L_LoadBitmapMemory with a different page each time?
unsigned WINAPI ConvertMultiImgToSingleImg(LPVOID param)
{
MultiToSingleThreadData * tInfo = (MultiToSingleThreadData *) param;
BITMAPHANDLE bmapHandle;
LOADFILEOPTION loadFileOptions;
FILEINFO fileInfo;
ZeroMemory(&loadFileOptions, sizeof(LOADFILEOPTION));
ZeroMemory(&bmapHandle, sizeof(BITMAPHANDLE));
ZeroMemory(&fileInfo, sizeof(FILEINFO));
UINT error = 0;
if(!Path::IsPathValid(tInfo->outputFilename))
error = IMG_CONV_ERROUTFNAME;
if(!Path::IsPathValid(tInfo->inputFilename))
error = IMG_CONV_ERRINFNAME;
else if(L_FileInfo(tInfo->inputFilename, &fileInfo, sizeof(FILEINFO), FILEINFO_TOTALPAGES, NULL) != SUCCESS)
error = IMG_CONV_FAILED;
else
{
tInfo->pageTotal = fileInfo.TotalPages;
tInfo->pageCurrent = 1;
}
if(tInfo->eventTotalPage != NULL)
SetEvent(tInfo->eventTotalPage);
if(error != 0)
{
_endthreadex(error);
return 0;
}
if(fileInfo.Format == FILE_RAS_PDF)
{
FILEPDFOPTIONS pdfOptions;
ZeroMemory(&pdfOptions, sizeof(FILEPDFOPTIONS));
if(L_GetPDFOptions(&pdfOptions, sizeof(FILEPDFOPTIONS)) != SUCCESS)
{
_endthreadex(IMG_CONV_FAILED);
return 0;
}
pdfOptions.nXResolution = 300;
pdfOptions.nYResolution = 300;
if(L_SetPDFOptions(&pdfOptions) != SUCCESS)
{
_endthreadex(IMG_CONV_FAILED);
return 0;
}
}
if(L_GetDefaultLoadFileOption(&loadFileOptions, sizeof(LOADFILEOPTION)) != SUCCESS)
{
_endthreadex(IMG_CONV_FAILED);
return 0;
}
stdstring fileNoExt, filePath;
try
{
fileNoExt = Path::GetFilenameNoExt(tInfo->outputFilename);
filePath = Path::GetPathNoFilename(tInfo->outputFilename);
tInfo->pagesConverted = 0;
for(int i = 1; i <= fileInfo.TotalPages; i++)
{
if(tInfo->stopConversion)
{
_endthreadex(IMG_CONV_STOPPED);
return 0;
}
ZeroMemory(tInfo->currentOutputFile, sizeof(tInfo->currentOutputFile));
_stprintf_s(tInfo->currentOutputFile, sizeof(tInfo->currentOutputFile), _T("%s.%.3d"), Path::Combine(filePath.c_str(), fileNoExt.c_str()).c_str(), i);
loadFileOptions.PageNumber = i;
tInfo->pageCurrent = i;
if(L_LoadBitmap(tInfo->inputFilename, &bmapHandle, sizeof(BITMAPHANDLE), 0, ORDER_RGB, &loadFileOptions, NULL) != SUCCESS)
continue;
if(L_SaveBitmap(tInfo->currentOutputFile, &bmapHandle, tInfo->outputFileType, 0, NULL, NULL) != SUCCESS)
{
L_FreeBitmap(&bmapHandle);
continue;
}
tInfo->pagesConverted++;
L_FreeBitmap(&bmapHandle);
}
}
catch(dferror &e)
{
}
_endthreadex(0);
return 0;
}