Sets the file options used by LEADTOOLS when rasterizing document files.
#include "ltwrappr.h"
static L_INT LFileSettings::SetRasterizeDocOptions(pRasterizeDocOptions)
Pointer to a structure that contains the options used when rasterizing document files.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
The values set by this function are valid for the current thread. To change the values used by the current thread, this function must be called again.
To get the current options used when rasterizing document files, call LFileSettings::GetRasterizeDocOptions.
Win32, x64.
L_CHAR* GetUnitName(RASTERIZEDOC_UNIT uUnit)
{
switch(uUnit)
{
case RASTERIZEDOC_UNIT_PIXEL: return "Pixel";
case RASTERIZEDOC_UNIT_INCH: return "Inch";
case RASTERIZEDOC_UNIT_MILLIMETER: "Millimeter";
default: return "";
}
}
L_VOID ShowResult(LBitmap* pBitmap)
{
RASTERIZEDOCOPTIONS rasterizeDocOptions;
L_DOUBLE pageWidthInPixels;
L_DOUBLE pageHeightInPixels;
ZeroMemory(&rasterizeDocOptions, sizeof(RASTERIZEDOCOPTIONS));
LFileSettings::GetRasterizeDocOptions(&rasterizeDocOptions, sizeof(RASTERIZEDOCOPTIONS));
printf("Showing result..\n");
printf(" Current rasterization options:\n");
printf(" Size mode is: ");
switch(rasterizeDocOptions.uSizeMode)
{
case RASTERIZEDOC_SIZEMODE_NONE: printf("None\n"); break;
case RASTERIZEDOC_SIZEMODE_FIT: printf("Fit\n"); break;
case RASTERIZEDOC_SIZEMODE_FIT_ALWAYS: printf("Fit always\n"); break;
case RASTERIZEDOC_SIZEMODE_FIT_WIDTH: printf("Fit width\n"); break;
case RASTERIZEDOC_SIZEMODE_STRETCH: printf("Stretch\n"); break;
}
printf(" Page size is %.3f by %.3f %s\n",
rasterizeDocOptions.dPageWidth, rasterizeDocOptions.dPageHeight, GetUnitName(rasterizeDocOptions.uUnit));
printf(" Resolution is %u by %u\n",
rasterizeDocOptions.uXResolution, rasterizeDocOptions.uYResolution);
printf(" Loaded raster image size is: %u by %u at %u by %u\n",
pBitmap->GetWidth(), pBitmap->GetHeight(), pBitmap->GetXResolution(), pBitmap->GetYResolution());
// Code to verify our results
// Get the suggested page width and height in pixels
switch(rasterizeDocOptions.uUnit)
{
case RASTERIZEDOC_UNIT_INCH:
pageWidthInPixels = rasterizeDocOptions.dPageWidth * rasterizeDocOptions.uXResolution;
pageHeightInPixels = rasterizeDocOptions.dPageHeight * rasterizeDocOptions.uYResolution;
break;
case RASTERIZEDOC_UNIT_MILLIMETER:
pageWidthInPixels = rasterizeDocOptions.dPageWidth * rasterizeDocOptions.uXResolution * 25.400000025908000026426160026955;
pageHeightInPixels = rasterizeDocOptions.dPageHeight * rasterizeDocOptions.uYResolution * 25.400000025908000026426160026955;
break;
case RASTERIZEDOC_UNIT_PIXEL:
default:
pageWidthInPixels = rasterizeDocOptions.dPageWidth;
pageHeightInPixels = rasterizeDocOptions.dPageHeight;
break;
}
// Verify
switch(rasterizeDocOptions.uSizeMode)
{
case RASTERIZEDOC_SIZEMODE_FIT:
case RASTERIZEDOC_SIZEMODE_FIT_ALWAYS:
// The image width/height must not be greater than suggested page width/height
printf("Image width/height must be less than or equal to page width/height\n");
assert(pBitmap->GetWidth() <= pageWidthInPixels);
assert(pBitmap->GetHeight() <= pageHeightInPixels);
break;
case RASTERIZEDOC_SIZEMODE_FIT_WIDTH:
// The image width must be equal to the suggested page width
printf("Image width must be equal to page width\n");
assert(pBitmap->GetWidth() == pageWidthInPixels);
break;
case RASTERIZEDOC_SIZEMODE_STRETCH:
// The image width/height must be equal to the suggested page width/height
printf("Image width/height must be equal to suggested page width/height\n");
assert(pBitmap->GetWidth() == pageWidthInPixels);
assert(pBitmap->GetHeight() == pageHeightInPixels);
break;
case RASTERIZEDOC_SIZEMODE_NONE:
default:
printf("Loading at original document page size");
// No checking
break;
}
}
L_INT LFileSettings__RasterizeDocumentExample()
{
// The PDF file we are testing. This could be an XPS, RTF, TXT or XLS file as well
L_TCHAR* pszImageFileName = MAKE_IMAGE_PATH(TEXT("PDFSegmentation.pdf"));
L_INT nRet = 0;
RASTERIZEDOCOPTIONS rasterizeDocOptions;
FILEINFO fileInfo;
LBitmap Bitmap;
LFile LeadFile;
LeadFile.SetBitmap(&Bitmap);
LeadFile.SetFileName(pszImageFileName);
ZeroMemory(&fileInfo, sizeof(FILEINFO));
// Enable using the RASTERIZEDOCOPTIONS
ZeroMemory(&rasterizeDocOptions, sizeof(RASTERIZEDOCOPTIONS));
nRet = LFileSettings::GetRasterizeDocOptions(&rasterizeDocOptions, sizeof(RASTERIZEDOCOPTIONS));
if(nRet != SUCCESS)
return nRet;
// No margins (only used with RTF and TXT files)
rasterizeDocOptions.dLeftMargin = 0;
rasterizeDocOptions.dTopMargin = 0;
rasterizeDocOptions.dRightMargin = 0;
rasterizeDocOptions.dBottomMargin = 0;
nRet = LFileSettings::SetRasterizeDocOptions(&rasterizeDocOptions);
if(nRet != SUCCESS)
return nRet;
// Show the file information
nRet = LeadFile.GetInfo(&fileInfo, sizeof(FILEINFO)) ;
if(nRet != SUCCESS)
return nRet;
// If this is a document file, show the document information
if(fileInfo.bIsDocFile)
{
printf("Document file\n");
printf(" Original size is: %.3f by %.3f %s\n",
fileInfo.dDocPageWidth, fileInfo.dDocPageHeight, GetUnitName(fileInfo.uDocUnit));
printf(" Using current rasterization, load size will be: %u by %u pixels at %u by %u\n",
fileInfo.Width, fileInfo.Height, fileInfo.XResolution, fileInfo.YResolution);
}
else
{
// Regular raster image, show the image information
printf("Raster file\n");
printf(" Original size is: %u by %u pixels at %u by %u\n",
fileInfo.Width, fileInfo.Height, fileInfo.XResolution, fileInfo.YResolution);
}
// Example 1. Load at original document size at 300 DPI
rasterizeDocOptions.uSizeMode = RASTERIZEDOC_SIZEMODE_NONE;
rasterizeDocOptions.uXResolution = 300;
rasterizeDocOptions.uYResolution = 300;
LFileSettings::SetRasterizeDocOptions(&rasterizeDocOptions);
nRet = Bitmap.Load(pszImageFileName, 0, ORDER_BGRORGRAY, NULL, NULL);
if(nRet != SUCCESS)
return nRet;
ShowResult(&Bitmap);
// Example 2. Fit the document at 640 by 480 pixels at 96 DPI keeping the aspect ratio
rasterizeDocOptions.uSizeMode = RASTERIZEDOC_SIZEMODE_FIT;
rasterizeDocOptions.dPageWidth = 640;
rasterizeDocOptions.dPageHeight = 480;
rasterizeDocOptions.uUnit = RASTERIZEDOC_UNIT_PIXEL;
rasterizeDocOptions.uXResolution = 96;
rasterizeDocOptions.uYResolution = 96;
nRet = Bitmap.Load(pszImageFileName, 0, ORDER_BGRORGRAY, NULL, NULL);
if(nRet != SUCCESS)
return nRet;
ShowResult(&Bitmap);
// Example 3. Fit the document at 8.5 by 11 inches at 96 DPI keeping the aspect ratio
rasterizeDocOptions.uSizeMode = RASTERIZEDOC_SIZEMODE_FIT;
rasterizeDocOptions.dPageWidth = 8.5;
rasterizeDocOptions.dPageHeight = 11;
rasterizeDocOptions.uUnit = RASTERIZEDOC_UNIT_INCH;
rasterizeDocOptions.uXResolution = 300;
rasterizeDocOptions.uYResolution = 300;
nRet = Bitmap.Load(pszImageFileName, 0, ORDER_BGRORGRAY, NULL, NULL);
if(nRet != SUCCESS)
return nRet;
ShowResult(&Bitmap);
// Example 4. Stretch the image to always be 4 by 4 inches at 150 DPI. Aspect ratio may differ
rasterizeDocOptions.uSizeMode = RASTERIZEDOC_SIZEMODE_STRETCH;
rasterizeDocOptions.dPageWidth = 4;
rasterizeDocOptions.dPageHeight = 4;
rasterizeDocOptions.uUnit = RASTERIZEDOC_UNIT_INCH;
rasterizeDocOptions.uXResolution = 150;
rasterizeDocOptions.uYResolution = 150;
nRet = Bitmap.Load(pszImageFileName, 0, ORDER_BGRORGRAY, NULL, NULL);
if(nRet != SUCCESS)
return nRet;
ShowResult(&Bitmap);
return SUCCESS;
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document