Products | Support | Send comments on this topic. | Email a link to this topic. | Back to Getting Started | Help Version 18.0.11.1
LEADTOOLS Raster Imaging C DLL Help

L_SetRasterizeDocOptions

Show in webframe

#include "l_bitmap.h"

L_LTFIL_API L_INT EXT_FUNCTION L_SetRasterizeDocOptions(pRasterizeDocOptions)

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 L_GetRasterizeDocOptions.

Required DLLs and Libraries

LTFIL
File format DLLs

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application .

Platforms

Win32, x64, Linux.

See Also

Functions:

L_GetRasterizeDocOptions

Topics:

Raster Image Functions: Loading Files

 

Loading and Saving Images

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.

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName


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(BITMAPHANDLE* pBitmap)
{
   RASTERIZEDOCOPTIONS rasterizeDocOptions;
   L_DOUBLE pageWidthInPixels;
   L_DOUBLE pageHeightInPixels;

   ZeroMemory(&rasterizeDocOptions, sizeof(RASTERIZEDOCOPTIONS));
   L_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",
      BITMAPWIDTH(pBitmap), BITMAPHEIGHT(pBitmap), pBitmap->XResolution, pBitmap->YResolution);

   // 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(BITMAPWIDTH(pBitmap) <= pageWidthInPixels);
         assert(BITMAPHEIGHT(pBitmap) <= 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(BITMAPWIDTH(pBitmap) == 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(BITMAPWIDTH(pBitmap) == pageWidthInPixels);
         assert(BITMAPHEIGHT(pBitmap) == pageHeightInPixels);
         break;

      case RASTERIZEDOC_SIZEMODE_NONE:
      default:
         printf("Loading at original document page size");
         // No checking
         break;
   }
}

 L_INT 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("Leadtools.pdf"));
   RASTERIZEDOCOPTIONS rasterizeDocOptions;
   FILEINFO fileInfo;
   BITMAPHANDLE bitmap;
   L_INT nRet = 0;

   ZeroMemory(&fileInfo, sizeof(FILEINFO));
   ZeroMemory(&bitmap, sizeof(BITMAPHANDLE));

   // Enable using the RASTERIZEDOCOPTIONS
   ZeroMemory(&rasterizeDocOptions, sizeof(RASTERIZEDOCOPTIONS));
   nRet = L_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 =  L_SetRasterizeDocOptions(&rasterizeDocOptions);
   if(nRet != SUCCESS)
      return nRet;

   // Show the file information
   nRet = L_FileInfo(pszImageFileName, &fileInfo, sizeof(FILEINFO), FILEINFO_TOTALPAGES, NULL);
   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;
   nRet = L_SetRasterizeDocOptions(&rasterizeDocOptions);
   if(nRet != SUCCESS)
      return nRet;

   nRet = L_LoadBitmap(pszImageFileName, &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;

   ShowResult(&bitmap);
   L_FreeBitmap(&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 = L_LoadBitmap(pszImageFileName, &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;

   ShowResult(&bitmap);
   L_FreeBitmap(&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 = L_LoadBitmap(pszImageFileName, &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;

   ShowResult(&bitmap);
   L_FreeBitmap(&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 = L_LoadBitmap(pszImageFileName, &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;

   ShowResult(&bitmap);
   L_FreeBitmap(&bitmap);

   return SUCCESS;
}
Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.