FILETXTOPTIONS

Summary

The FILETXTOPTIONS structure provides information on loading TXT files in LEADTOOLS.

Syntax

typedef struct _FILETXTOPTIONS 
{ 
   L_UINT uStructSize; 
   L_BOOL bEnabled; 
   L_COLORREF crFontColor; 
   L_COLORREF crHighlight; 
   L_INT nFontSize; 
   L_TCHAR szFaceName[LF_FACESIZE]; 
   L_BOOL bBold; 
   L_BOOL bItalic; 
   L_BOOL bUnderLine; 
   L_BOOL bStrikeThrough; 
   L_TEXT_ENCODING defaultEncoding; 
   L_COLORREF crBackColor; 
   L_TEXT_ANTI_ALIASING antiAliasing; 
   L_BOOL bWrap; 
   L_UINT uTabSize; 
   L_UINT uFlags; 
   L_DOUBLE dMinPageWidth; 
   L_DOUBLE dMinPageHeight; 
} FILETXTOPTIONS, *pFILETXTOPTIONS; 

Members

uStructSize

Size of the structure. This must be set before passing this structure to the LEAD functions. Use sizeof(FILETXTOPTIONS) to calculate this value.

bEnabled

Flag that indicates whether to call the filter. Possible values are:

Value Meaning
TRUE Call the filter.
FALSE Do not call the filter.

crFontColor

The font color.

crHighlight

The high light color. Highlight is the color used as background for the text paragraphs found in the file. If you do not want to show the highlight color, set its value to the same as crFontColor or crBackColor.

nFontSize

The font size in points.

szFaceName

Character string that contains the text font face name.

antiAliasing

Indicates whether anti-aliasing should be used when drawing text. Possible values are:

Value Meaning
L_TEXT_ANTI_ALIASING_AUTO Let LEADTOOLS pick when to use anti-aliasing (Default). In this case, anti-aliasing is enabled when loading at >= 8 bpp and disabled for < 8 bpp.
L_TEXT_ANTI_ALIASING_ON Anti-aliasing is always on.
L_TEXT_ANTI_ALIASING_OFF Anti-aliasing is always off.

bBold

Flag that indicates whether to display the text as bold. Possible values are:

Value Meaning
TRUE Displays the text as bold.
FALSE Displays the text as not bold.

bItalic

Flag that indicates whether to display the text as italic. Possible values are:

Value Meaning
TRUE Displays the text as italic.
FALSE Displays the text as not italic.

bUnderLine

Flag that indicates whether to display the text underlined. Possible values are:

Value Meaning
TRUE Displays the text underlined.
FALSE Displays the text as not underlined.

bStrikeThrough

Flag that indicates whether to display the text with a strikethrough. Possible values are:

Value Meaning
TRUE Displays the text with a strikethrough.
FALSE Displays the text without a strikethrough.

bWrap

Flag that indicates whether long lines of text should be wrapped into several lines or truncated. Possible values are:

Value Meaning
TRUE Split long text lines into several rows (default).
FALSE Truncate long lines of text.

defaultEncoding

The text encoding for files without a byte-order mark (BOM). See L_TEXT_ENCODING for possible values.

This setting is ignored when loading files containing a BOM.

You can check whether a file has a BOM by getting the file information and examining whether FILEINFO.Flags contains the FILEINFO_HAS_BOM flag.

crBackColor

The background color. Background is the color used to fill the result image before rending the text on top of it.

uTabSize

The length of the spaces used for the tab character. Default is 4.

This value is used to replace a tab character in a text.

If set to 0, the tab will not be replaced. The result will depend on the drawing engine used to render the text.

uFlags

Various bit flags are used to influence the load. The following flags are defined:

Value Meaning
L_TEXT_FLAGS_VARIABLE_WIDTH [0x0001] If set, the output width is calculated from the longest line in the file. In this case, FILETXTOPTIONS.bWrap and dPageWidth are ignored. If not set, the output width is indicated by dPageWidth. This is the default.
L_TEXT_FLAGS_VARIABLE_HEIGHT [0x0002] If set, the output height is calculated so the whole text file will be loaded as one page. In this case, dPageHeight is ignored. If not set, the page height is indicated by dPageHeight. This is the default.

The default value for uFlags is 0 (no flag is set).

dMinPageWidth

If >0, minimum page width, using units from RASTERIZEDOCOPTIONS.uUnit.

If 0, there is no minimum page width.

dMinPageHeight

If >0, minimum page height, using units from RASTERIZEDOCOPTIONS.uUnit.

If 0, there is no minimum page height.

Comments

pFILETXTOPTIONS is a pointer to a FILETXTOPTIONS structure.

Text files have no physical width or height in pixels. You can use RASTERIZEDOCOPTIONS to control how the final document is rendered as a raster image or as an SVG.

By default LEADTOOLS has set the page size to 8.5" x 11" (width x height in inches). To change the default page size use dPageWidth and dPageHeight properties. To change the units of measure, use RASTERIZEDOC_UNIT.

Although it is possible to enable both L_TEXT_FLAGS_VARIABLE_WIDTH and L_TEXT_FLAGS_VARIABLE_HEIGHT on a given page, it is not recommended. Enabling both, can result in a very large page size that reduces responsiveness and consumes more contiguous memory. Conversely, enabling either property, not both, can produce better performance for smaller page size.

The document or image width is set as follows:

The document or image height is set as follows:

L_TEXT_FLAGS_VARIABLE_WIDTH and L_TEXT_FLAGS_VARIABLE_HEIGHT allow the default page size to expand when the page content is larger. If L_TEXT_FLAGS_VARIABLE_WIDTH is set in uFlags, the FILETXTOPTIONS.dMinPageWidth property allows the user to specify a minimum width. And if L_TEXT_FLAGS_VARIABLE_HEIGHT is set in uFlags, the FILETXTOPTIONS.dMinPageHeight property allows the user to specify a minimum height.

Recommendation on Using L_TEXT_FLAGS_VARIABLE_WIDTH and L_TEXT_FLAGS_VARIABLE_HEIGHT

To illustrate the interaction of these properties and provide a recommendation, below there is a list of various cases and their results for L_TEXT_FLAGS_VARIABLE_WIDTH and L_TEXT_FLAGS_VARIABLE_HEIGHT properties. A sample text with 16 columns x 100 rows is used which exceeds the width and height of the default page size. The column-row arrangement must be preserved in the output. Text wrapping or trimming are undesirable in the output. The top row and last row are reproduced below (Download sample file).

Input's First Row

row1column1			row1column2			row1column3			row1column4			row1column5			row1column6			row1column7			row1column8			 row1column9			row1column10			row1column11			row1column12			row1column13			row1column14			row1column15			row1column16			  

Input's Last Row

row100column1			row100column2			row100column3			row100column4			row100column5			row100column6			row100column7			row100colum8			row100column9			row100column10			row100column11			row100column12			row100column13			row100column14			row100column15			row100column16			 

Case 1 (Recommended)

Properties: L_TEXT_FLAGS_VARIABLE_WIDTH, L_TEXT_FLAGS_VARIABLE_HEIGHT set in uFlags

Result: The column-row format from the input is preserved. The width property is unrestricted and each column preserves the original format. Notice that these entries are in the correct row: row1column1, row2column1, row3column1, etc. The page height property is restricted to default size. The result is data separated by page size that includes all input columns and rows. The output is saved over three pages using the default height.

Download sample PDF file.

Case 2 (Second Best Recommended)

Properties: L_TEXT_FLAGS_VARIABLE_WIDTH, L_TEXT_FLAGS_VARIABLE_HEIGHT set in uFlags

Result: The column-row format from the input is preserved. The width property is unrestricted and each column preserves the original format. Notice that these entries are in the correct row: row1column1, row2column1, row3column1,...,row100column1. The page height property is unrestricted. The result is a single image for all data. This is the case where caution must be exercised as very large data is contained on a single output page.

Download sample PDF file.

Case 3 (Undesirable Scenario)

Properties: L_TEXT_FLAGS_VARIABLE_WIDTH, L_TEXT_FLAGS_VARIABLE_HEIGHT set in uFlags

Result: The column-row format from the input is not preserved. Both, width and height properties, are restricted to the default size and any columns beyond the default width are wrapped to the next row as is the case for row1column4.

Download sample PDF file.

Case 4 (Undesirable Scenario)

Properties: L_TEXT_FLAGS_VARIABLE_WIDTH, L_TEXT_FLAGS_VARIABLE_HEIGHT set in uFlags

Result: The column-row format from the input is not preserved. The width property is restricted to the default size and any columns beyond the default width are wrapped to the next row as is the case for row1column4.

Download sample PDF file.

dMinPageWidth and dMinPageHeight Usage

To illustrate the interaction of these properties, refer to the list below of four cases and their results for dMinPageWidth and dMinPageHeight properties. A sample text with 2 columns x 10 rows is used, which is well within the width and height values of the default page size. In general, the specific setting combination to use for these properties depends on the user's preference. However, the properties are suitable for files with page width or height dimensions that are less than the default minimum. Use these four cases as a quick preview of results under different scenarios.

The top row and last row are reproduced below (Download sample file).

Input's First Row

row1column1			row1column2 

Input's Last Row

row10column1			row10column2 

Case 1

Properties: dMinPageWidth = 8.5, dMinPageHeight = 11

Result: The column-row format and data from the input are preserved. Setting the minimum page width to 8.5 and minimum height to 11 result in output that includes all column-row format and data within the defined page height and width.

Download sample PDF file.

Case 2

Properties: dMinPageWidth = 0, dMinPageHeight = 11

Result: The column-row format and data from the input are preserved. Setting the minimum page width to 0 and minimum height to 11 result in output that includes all column-row format and data within the defined page height and width.

Download sample PDF file.

Case 3

Properties: dMinPageWidth = 8.5, dMinPageHeight = 0

Result: The column-row format from the input is preserved. Setting the minimum page width to 8.5 and minimum height to 0, the format and data are preserved within the specified dimensions.

Download sample PDF file.

Case 4

Properties: dMinPageWidth = 0, dMinPageHeight = 0

Result: The column-row format from the input is preserved. The data and format are preserved within the smallest dimensions.

Download sample PDF file.

Example

L_INT SaveOutputPDF(L_TCHAR * pszSource, 
   L_TCHAR * pszDest, 
   FILETXTOPTIONS filTxtOptions, 
   SAVEFILEOPTION saveFileOption, 
   LOADFILEOPTION loadFileOption, 
   L_INT bitsPerPixel, 
   L_INT qualityFactor) 
{ 
   //Save PDF 
   FILEINFO fileInfo; 
   L_FileInfo((TCHAR*)pszSource, &fileInfo, sizeof FILEINFO, FILEINFO_TOTALPAGES, NULL); 
   L_INT ret = FAILURE; 
   for (int i = 1; i <= fileInfo.TotalPages; ++i) 
   { 
      BITMAPHANDLE bitmap; 
      loadFileOption.PageNumber = i; 
      ret = L_LoadBitmap((L_TCHAR*)pszSource, &bitmap, sizeof BITMAPHANDLE, bitsPerPixel, ORDER_RGB, &loadFileOption, &fileInfo); 
      if (ret != SUCCESS) 
         return ret; 
 
      saveFileOption.PageNumber = i; 
      ret = L_SaveBitmap((L_TCHAR*)pszDest, &bitmap, FILE_RAS_PDF_JBIG2, bitsPerPixel, qualityFactor, &saveFileOption); 
      if (ret != SUCCESS) 
         return ret; 
 
      if (bitmap.Flags.Allocated) 
         L_FreeBitmap(&bitmap); 
   } 
 
   return ret; 
} 
 
L_INT PageMinWidthHeightExample(L_VOID) 
{ 
   /*Define Variables*/ 
   L_INT ret = FAILURE; 
   int bitsPerPixel = 1; 
   int qualityFactor = 2; 
   FILETXTOPTIONS fileTxtOptions; 
   SAVEFILEOPTION saveFileOption; 
   LOADFILEOPTION loadFileOption; 
 
   ret = L_GetDefaultSaveFileOption(&saveFileOption, sizeof(SAVEFILEOPTION)); 
   if (ret != SUCCESS) 
      return ret; 
 
   ret = L_GetDefaultLoadFileOption(&loadFileOption, sizeof(LOADFILEOPTION)); 
   if (ret != SUCCESS) 
      return ret; 
 
   loadFileOption.Flags = LOADFILE_ALLPAGES; 
   saveFileOption.Flags = SAVEFILE_MULTIPAGE; 
 
   /*Set Text file options*/ 
   ret = L_GetTXTOptions(&fileTxtOptions, sizeof(FILETXTOPTIONS)); 
   if (ret != SUCCESS) 
      return ret; 
 
   //Text Options 
   fileTxtOptions.dMinPageWidth = 0; 
   fileTxtOptions.dMinPageHeight = 0; 
   fileTxtOptions.uTabSize = 8; 
 
   /**************************************************************************************  
   * Large Data Set: Source text contains 16 columns x 100 rows 
   * Default: 
   *  dMinPageWidth = 0; 
   *  dMinPageHeight = 0; 
   * Case 1:  
   * L_TEXT_FLAGS_VARIABLE_WIDTH | !L_TEXT_FLAGS_VARIABLE_HEIGHT 
   *  
   * Case 2:  
   * L_TEXT_FLAGS_VARIABLE_WIDTH | L_TEXT_FLAGS_VARIABLE_HEIGHT 
   *  
   * Case 3: 
   * !L_TEXT_FLAGS_VARIABLE_WIDTH | !L_TEXT_FLAGS_VARIABLE_HEIGHT 
   *  
   * Case 4: 
   * !L_TEXT_FLAGS_VARIABLE_WIDTH | L_TEXT_FLAGS_VARIABLE_HEIGHT 
   ***************************************************************************************/ 
 
   L_TCHAR sourceFile[_MAX_PATH]; 
   wsprintf(sourceFile, MAKE_IMAGE_PATH("Columns-Big.txt")); 
 
   /* 
   *   Case 1: L_TEXT_FLAGS_VARIABLE_WIDTH | !L_TEXT_FLAGS_VARIABLE_HEIGHT 
   */ 
   fileTxtOptions.uFlags = L_TEXT_FLAGS_VARIABLE_WIDTH | !L_TEXT_FLAGS_VARIABLE_HEIGHT; 
   ret = L_SetTXTOptions(&fileTxtOptions); 
   if (ret != SUCCESS) 
      return ret; 
 
   L_TCHAR destFile[_MAX_PATH]; 
   wsprintf(destFile, MAKE_IMAGE_PATH("LargeDataSetTest1.pdf")); 
 
   ret = SaveOutputPDF(sourceFile, destFile, fileTxtOptions, saveFileOption, loadFileOption, bitsPerPixel, qualityFactor); 
   if (ret != SUCCESS) 
      return ret; 
       
   /* 
   *   Case 2: L_TEXT_FLAGS_VARIABLE_WIDTH | L_TEXT_FLAGS_VARIABLE_HEIGHT 
   */ 
   fileTxtOptions.uFlags = L_TEXT_FLAGS_VARIABLE_WIDTH | L_TEXT_FLAGS_VARIABLE_HEIGHT; 
   ret = L_SetTXTOptions(&fileTxtOptions); 
   if (ret != SUCCESS) 
      return ret; 
 
   wsprintf(destFile, MAKE_IMAGE_PATH("LargeDataSetTest2.pdf")); 
 
   ret = SaveOutputPDF(sourceFile, destFile, fileTxtOptions, saveFileOption, loadFileOption, bitsPerPixel, qualityFactor); 
   if (ret != SUCCESS) 
      return ret; 
 
   /* 
   *   Case 3: !L_TEXT_FLAGS_VARIABLE_WIDTH | !L_TEXT_FLAGS_VARIABLE_HEIGHT 
   */ 
   fileTxtOptions.uFlags = !L_TEXT_FLAGS_VARIABLE_WIDTH | !L_TEXT_FLAGS_VARIABLE_HEIGHT; 
   ret = L_SetTXTOptions(&fileTxtOptions); 
   if (ret != SUCCESS) 
      return ret; 
 
   wsprintf(destFile, MAKE_IMAGE_PATH("LargeDataSetTest3.pdf")); 
 
   ret = SaveOutputPDF(sourceFile, destFile, fileTxtOptions, saveFileOption, loadFileOption, bitsPerPixel, qualityFactor); 
   if (ret != SUCCESS) 
      return ret; 
 
   /* 
   *   Case 4: !L_TEXT_FLAGS_VARIABLE_WIDTH | L_TEXT_FLAGS_VARIABLE_HEIGHT 
   */ 
   fileTxtOptions.uFlags = !L_TEXT_FLAGS_VARIABLE_WIDTH | L_TEXT_FLAGS_VARIABLE_HEIGHT; 
   ret = L_SetTXTOptions(&fileTxtOptions); 
   if (ret != SUCCESS) 
      return ret; 
 
   wsprintf(destFile, MAKE_IMAGE_PATH("LargeDataSetTest4.pdf")); 
 
   ret = SaveOutputPDF(sourceFile, destFile, fileTxtOptions, saveFileOption, loadFileOption, bitsPerPixel, qualityFactor); 
   if (ret != SUCCESS) 
      return ret; 
 
   /************************************************************************************** 
   * Large Data Set: Source text contains 16 columns x 100 rows 
   * Text Flags: 
   *  L_TEXT_FLAGS_VARIABLE_WIDTH 
   *  L_TEXT_FLAGS_VARIABLE_HEIGHT 
   * Case 1: 
   *  dMinPageWidth = 8.5; 
   *  dMinPageHeight = 11; 
   * Case 2: 
   *  dMinPageWidth = 0; 
   *  dMinPageHeight = 11; 
   * Case 3: 
   *  dMinPageWidth = 8.5; 
   *  dMinPageHeight = 0; 
   * Case 4: 
   *  dMinPageWidth = 0; 
   *  dMinPageHeight = 0; 
   ***************************************************************************************/ 
 
   wsprintf(sourceFile, MAKE_IMAGE_PATH("Columns-Small.txt")); 
    
   /* 
   *   Case 1: dMinPageWidth = 8.5,  | dMinPageHeight = 11 
   */ 
   fileTxtOptions.uFlags = L_TEXT_FLAGS_VARIABLE_WIDTH | L_TEXT_FLAGS_VARIABLE_HEIGHT; 
   fileTxtOptions.dMinPageWidth = 8.5; 
   fileTxtOptions.dMinPageHeight = 11; 
   ret = L_SetTXTOptions(&fileTxtOptions); 
   if (ret != SUCCESS) 
      return ret; 
 
   wsprintf(destFile, MAKE_IMAGE_PATH("SmallDataSetTest1.pdf")); 
 
   ret = SaveOutputPDF(sourceFile, destFile, fileTxtOptions, saveFileOption, loadFileOption, bitsPerPixel, qualityFactor); 
   if (ret != SUCCESS) 
      return ret; 
 
   /* 
   *   Case 2: dMinPageWidth = 0,  | dMinPageHeight = 11 
   */ 
   fileTxtOptions.uFlags = L_TEXT_FLAGS_VARIABLE_WIDTH | L_TEXT_FLAGS_VARIABLE_HEIGHT; 
   fileTxtOptions.dMinPageWidth = 0; 
   fileTxtOptions.dMinPageHeight = 11; 
   ret = L_SetTXTOptions(&fileTxtOptions); 
   if (ret != SUCCESS) 
      return ret; 
 
   wsprintf(destFile, MAKE_IMAGE_PATH("SmallDataSetTest2.pdf")); 
   ret = SaveOutputPDF(sourceFile, destFile, fileTxtOptions, saveFileOption, loadFileOption, bitsPerPixel, qualityFactor); 
   if (ret != SUCCESS) 
      return ret; 
 
   /* 
   *   Case 3: dMinPageWidth = 8.5,  | dMinPageHeight = 0 
   */ 
   fileTxtOptions.uFlags = L_TEXT_FLAGS_VARIABLE_WIDTH | L_TEXT_FLAGS_VARIABLE_HEIGHT; 
   fileTxtOptions.dMinPageWidth = 8.5; 
   fileTxtOptions.dMinPageHeight = 0; 
   ret = L_SetTXTOptions(&fileTxtOptions); 
   if (ret != SUCCESS) 
      return ret; 
 
   wsprintf(destFile, MAKE_IMAGE_PATH("SmallDataSetTest3.pdf")); 
   ret = SaveOutputPDF(sourceFile, destFile, fileTxtOptions, saveFileOption, loadFileOption, bitsPerPixel, qualityFactor); 
   if (ret != SUCCESS) 
      return ret; 
 
   /* 
   *   Case 4: dMinPageWidth = 0,  | dMinPageHeight = 0 
   */ 
   fileTxtOptions.uFlags = L_TEXT_FLAGS_VARIABLE_WIDTH | L_TEXT_FLAGS_VARIABLE_HEIGHT; 
   fileTxtOptions.dMinPageWidth = 0; 
   fileTxtOptions.dMinPageHeight = 0; 
   ret = L_SetTXTOptions(&fileTxtOptions); 
   if (ret != SUCCESS) 
      return ret; 
 
   wsprintf(destFile, MAKE_IMAGE_PATH("SmallDataSetTest4.pdf")); 
   ret = SaveOutputPDF(sourceFile, destFile, fileTxtOptions, saveFileOption, loadFileOption, bitsPerPixel, qualityFactor); 
   if (ret != SUCCESS) 
      return ret; 
 
   return ret; 
} 

Usage

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.