Available in LEADTOOLS Imaging Pro, Vector, Document, and Medical Imaging toolkits. |
LFileSettings::SetRasterizeDocOptions
#include "ltwrappr.h"
static L_INT LFileSettings::SetRasterizeDocOptions(pRasterizeDocOptions)
const pRASTERIZEDOCOPTIONS pRasterizeDocOptions; |
/* pointer to a structure */ |
Sets the file options used by LEADTOOLS when rasterizing document files.
Parameter |
Description |
pRasterizeDocOptions |
Pointer to a structure that contains the options used when rasterizing document files. |
Returns
SUCCESS |
The function was successful. |
< 1 |
An error occurred. Refer to Return Codes. |
Comments
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.
Required DLLs and Libraries
LTFIL For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application. |
Win32, x64.
See Also
Functions: |
|
Topics: |
|
|
Example
This example will load a PDF document using different rasterize document options and show its effect on the result raster bitmap handle width, height and resolution.
static const 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 ""; } } static 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_VOID RasterizeDocumentExample() { // The PDF file we are testing. This could be an XPS, RTF, TXT or XLS file as well L_TCHAR* pszImageFileName = TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\Leadtools.pdf"); RASTERIZEDOCOPTIONS rasterizeDocOptions; FILEINFO fileInfo; LBitmap* pBitmap; LFile LeadFile; LeadFile.SetBitmap(pBitmap); LeadFile.SetFileName(pszImageFileName); ZeroMemory(&fileInfo, sizeof(FILEINFO)); ZeroMemory(&bitmap, sizeof(BITMAPHANDLE)); // Unlock support for loading raster PDF files LSettings::UnlockSupport(L_SUPPORT_PDF_READ, TEXT("Your key here")); // Enable using the RASTERIZEDOCOPTIONS ZeroMemory(&rasterizeDocOptions, sizeof(RASTERIZEDOCOPTIONS)); LFileSettings::GetRasterizeDocOptions(&rasterizeDocOptions, sizeof(RASTERIZEDOCOPTIONS)); rasterizeDocOptions.bEnabled = L_TRUE; // No margins (only used with RTF and TXT files) rasterizeDocOptions.dLeftMargin = 0; rasterizeDocOptions.dTopMargin = 0; rasterizeDocOptions.dRightMargin = 0; rasterizeDocOptions.dBottomMargin = 0; LFileSettings::SetRasterizeDocOptions(&rasterizeDocOptions); // Show the file information LeadFile.GetInfo(&fileInfo, sizeof(FILEINFO)) ; // 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); pBitmap->Load(pszImageFileName, 0, ORDER_BGRORGRAY, NULL, NULL); ShowResult(pBitmap); // 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; pBitmap->Load(pszImageFileName, 0, ORDER_BGRORGRAY, NULL, NULL); ShowResult(pBitmap); // 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; pBitmap->Load(pszImageFileName, 0, ORDER_BGRORGRAY, NULL, NULL); ShowResult(pBitmap); // 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; pBitmap->Load(pszImageFileName, 0, ORDER_BGRORGRAY, NULL, NULL); ShowResult(pBitmap); }