←Select platform

VariableHeight Property

Summary

Indicates whether the height of the output should be variable or equal to CodecsRasterizeDocumentLoadOptions.PageHeight.

Syntax

C#
Objective-C
C++/CLI
Java
Python
public bool VariableHeight { get; set; } 
@property (nonatomic, assign) BOOL variableHeight; 
public boolean isVariableHeight() 
public void setVariableHeight(boolean variableHeight) 
public:  
   property bool VariableHeight 
   { 
      bool get() 
      void set(bool value) 
   } 
VariableHeight # get and set (CodecsTxtLoadOptions) 

Property Value

Value Description
true Load the text as a single page whose height is equal to the CodecsRasterizeDocumentLoadOptions.TopMargin + the total height of all the text lines in the file + CodecsRasterizeDocumentLoadOptions.BottomMargin , specified in CodecsRasterizeDocumentLoadOptions. CodecsRasterizeDocumentLoadOptions.PageHeight is ignored. Use with caution! Some files contain a lot of data and setting VariableHeight = true, may result in images with a large height, that require a lot of memory, and may take a long time to load.
false The height of each page will be equal to CodecsRasterizeDocumentLoadOptions.PageHeight. Files containing text line length that exceed CodecsRasterizeDocumentLoadOptions.PageHeight might be loaded over several pages. The default value is false.

Remarks

The VariableWidth and VariableHeight properties allow the default page size to expand when the page content is larger. If VariableWidth is set to true, the MinimumPageWidth property allows the user to specify a minimum width. And if VariableHeight is set to true, the MinimumPageHeight property allows the user to specify a minimum height.

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 RasterCodecs.Options.RasterizeDocument.Load.PageWidth and RasterCodecs.Options.RasterizeDocument.Load.PageHeight properties. To change the units of measure, use RasterCodecs.Options.RasterizeDocument.Load.Unit.

Although it is possible to enable both VariableWidth and VariableHeight 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.

Recommendation on Using VariableWidth and VariableHeight

To illustrate the interaction of these properties and provide a recommendation, below there is a list of various cases and their results for VariableWidth and VariableHeight 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: VariableWidth = true, VariableHeight = false

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: VariableWidth = true, VariableHeight = true

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: VariableWidth = false, VariableHeight = false

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: VariableWidth = false, VariableHeight = true

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.

MinimumPageWidth and MinimumPageHeight Usage

To illustrate the interaction of these properties, refer to the list below of four cases and their results for MinimumPageWidth and MinimumPageHeight 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: MinimumPageWidth = 8.5, MinimumPageHeight = 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: MinimumPageWidth = 0, MinimumPageHeight = 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: MinimumPageWidth = 8.5, MinimumPageHeight = 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: MinimumPageWidth = 0, MinimumPageHeight = 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

C#
using Leadtools; 
using Leadtools.Codecs; 
 
using Leadtools.ImageProcessing.Core; 
using Leadtools.Pdf; 
 
 
/*  
* This example loads a text file as a single page.  
* The text is not wrapped and the width and height  
* of the image are determined by the contents of the source file.  
*/ 
public void TestLoadText() 
{ 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
 
      /* Output as PDF will need optimization 
       *  1. Set the path to the PDF utilities dll 
       *  2. Use PDFOptimizerOptions to optimize the size of the output PDF 
      */ 
      codecs.Options.Pdf.InitialPath = @"C:\LEADTOOLS22\Bin\Dotnet4\x64"; 
      PDFOptimizerOptions myOptimizerOptions = new PDFOptimizerOptions(); 
      myOptimizerOptions.AutoOptimizerMode = PDFAutoOptimizerMode.GoodQuality; 
      myOptimizerOptions.ColorImageDownsamplingMode = PDFDownsamplingMode.Average; 
      myOptimizerOptions.GrayImageDownsamplingMode = PDFDownsamplingMode.Bicubic; 
      myOptimizerOptions.MonoImageDownsamplingMode = PDFDownsamplingMode.Bicubic; 
      myOptimizerOptions.ColorImageDownsampleFactor = 2.0; 
      myOptimizerOptions.GrayImageDownsampleFactor = 2.0; 
      myOptimizerOptions.MonoImageDownsampleFactor = 2.0; 
      myOptimizerOptions.ColorImageDPI = 150; 
      myOptimizerOptions.GrayImageDPI = 150; 
      myOptimizerOptions.MonoImageDPI = 150; 
      myOptimizerOptions.ColorImageCompression = RasterImageFormat.Jpeg; 
      myOptimizerOptions.GrayImageCompression = RasterImageFormat.RasPdfLzw; 
      myOptimizerOptions.MonoImageCompression = RasterImageFormat.Jbig; 
      myOptimizerOptions.EmbedAllFonts = false; 
      myOptimizerOptions.SubsetFonts = true; 
 
      /* 
       * Large Number of Columns and Rows Data Set 
      */ 
 
      string srcFile = Path.Combine(LEAD_VARS.ImagesDir, @"Columns-Big.txt"); 
             
      //Test 1: VariableWidth = true, VariableHeight = false 
      string dstFile = Path.Combine(LEAD_VARS.ImagesDir, @"Test1LargeDataSet.pdf"); 
      codecs.Options.Txt.Load.VariableWidth = true; 
      codecs.Options.Txt.Load.VariableHeight = false; 
      using (RasterImage img = codecs.Load(srcFile, 1)) 
      { 
         codecs.Save(img, dstFile, RasterImageFormat.RasPdfJpeg, 0); 
                
         //Optimize 
         PDFFile _pdf = new PDFFile(dstFile); 
         _pdf.OptimizerOptions = myOptimizerOptions; 
         _pdf.Optimize(dstFile); 
 
      } 
 
      //Test 2: VariableWidth = true, VariableHeight = true 
      dstFile = Path.Combine(LEAD_VARS.ImagesDir, @"Test2LargeDataSet.pdf"); 
      codecs.Options.Txt.Load.VariableWidth = true; 
      codecs.Options.Txt.Load.VariableHeight = true; 
      using (RasterImage img = codecs.Load(srcFile, 1)) 
      { 
         codecs.Save(img, dstFile, RasterImageFormat.RasPdf, 0); 
 
         //Optimize 
         PDFFile _pdf = new PDFFile(dstFile); 
         _pdf.OptimizerOptions = myOptimizerOptions; 
         _pdf.Optimize(dstFile); 
      } 
 
      //Test 3: VariableWidth = false, VariableHeight = false 
      dstFile = Path.Combine(LEAD_VARS.ImagesDir, @"Test3LargeDataSet.pdf"); 
      codecs.Options.Txt.Load.VariableWidth = false; 
      codecs.Options.Txt.Load.VariableHeight = false; 
      using (RasterImage img = codecs.Load(srcFile, 1)) 
      { 
         codecs.Save(img, dstFile, RasterImageFormat.RasPdf, 0); 
 
         //Optimize 
         PDFFile _pdf = new PDFFile(dstFile); 
         _pdf.OptimizerOptions = myOptimizerOptions; 
         _pdf.Optimize(dstFile); 
      } 
 
      //Test 4: VariableWidth = false, VariableHeight = true 
      dstFile = Path.Combine(LEAD_VARS.ImagesDir, @"Test4LargeDataSet.pdf"); 
      codecs.Options.Txt.Load.VariableWidth = false; 
      codecs.Options.Txt.Load.VariableHeight = true; 
      using (RasterImage img = codecs.Load(srcFile, 1)) 
      { 
         codecs.Save(img, dstFile, RasterImageFormat.RasPdf, 0); 
 
         //Optimize 
         PDFFile _pdf = new PDFFile(dstFile); 
         _pdf.OptimizerOptions = myOptimizerOptions; 
         _pdf.Optimize(dstFile); 
      } 
 
      /* 
       * Small Number of Columns and Rows Data Set 
      */ 
 
      srcFile = Path.Combine(LEAD_VARS.ImagesDir, @"Columns-Small.txt"); 
 
      //Test 5: MinimumPageWidth = 8.5, MinimumPageHeight = 11 
      dstFile = Path.Combine(LEAD_VARS.ImagesDir, @"Test5SmallDataSet.pdf"); 
      codecs.Options.Txt.Load.VariableWidth = true; 
      codecs.Options.Txt.Load.VariableHeight = true; 
      codecs.Options.Txt.Load.MinimumPageWidth = 8.5; 
      codecs.Options.Txt.Load.MinimumPageHeight = 11.0; 
 
      using (RasterImage img = codecs.Load(srcFile, 1)) 
      { 
         codecs.Save(img, dstFile, RasterImageFormat.RasPdf, 0); 
 
         //Optimize 
         PDFFile _pdf = new PDFFile(dstFile); 
         _pdf.OptimizerOptions = myOptimizerOptions; 
         _pdf.Optimize(dstFile); 
      } 
 
      //Test 6: MinimumPageWidth = 0, MinimumPageHeight = 11.0 
      dstFile = Path.Combine(LEAD_VARS.ImagesDir, @"Test6SmallDataSet.pdf"); 
      codecs.Options.Txt.Load.VariableWidth = true; 
      codecs.Options.Txt.Load.VariableHeight = true; 
      codecs.Options.Txt.Load.MinimumPageWidth = 0; 
      codecs.Options.Txt.Load.MinimumPageHeight = 11.0; 
 
      using (RasterImage img = codecs.Load(srcFile, 1)) 
      { 
         codecs.Save(img, dstFile, RasterImageFormat.RasPdf, 0); 
 
         //Optimize 
         PDFFile _pdf = new PDFFile(dstFile); 
         _pdf.OptimizerOptions = myOptimizerOptions; 
         _pdf.Optimize(dstFile); 
      } 
 
      //Test 7: MinimumPageWidth = 8.5, MinimumPageHeight = 0 
      dstFile = Path.Combine(LEAD_VARS.ImagesDir, @"Test7SmallDataSet.pdf"); 
      codecs.Options.Txt.Load.VariableWidth = true; 
      codecs.Options.Txt.Load.VariableHeight = true; 
      codecs.Options.Txt.Load.MinimumPageWidth = 8.5; 
      codecs.Options.Txt.Load.MinimumPageHeight = 0; 
      using (RasterImage img = codecs.Load(srcFile, 1)) 
      { 
         codecs.Save(img, dstFile, RasterImageFormat.RasPdf, 0); 
 
         //Optimize 
         PDFFile _pdf = new PDFFile(dstFile); 
         _pdf.OptimizerOptions = myOptimizerOptions; 
         _pdf.Optimize(dstFile); 
      } 
 
      //Test 8: MinimumPageWidth = 0, MinimumPageHeight = 0 
      dstFile = Path.Combine(LEAD_VARS.ImagesDir, @"Test8SmallDataSet.pdf"); 
      codecs.Options.Txt.Load.VariableWidth = true; 
      codecs.Options.Txt.Load.VariableHeight = true; 
      codecs.Options.Txt.Load.MinimumPageWidth = 0; 
      codecs.Options.Txt.Load.MinimumPageHeight = 0; 
      using (RasterImage img = codecs.Load(srcFile, 1)) 
      { 
         codecs.Save(img, dstFile, RasterImageFormat.RasPdf, 0); 
 
         //Optimize 
         PDFFile _pdf = new PDFFile(dstFile); 
         _pdf.OptimizerOptions = myOptimizerOptions; 
         _pdf.Optimize(dstFile); 
      } 
 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 

Requirements

Target Platforms

See Also

CodecsTxtLoadOptions.VariableWidth
CodecsRasterizeDocumentLoadOptions.TopMargin
CodecsRasterizeDocumentLoadOptions.BottomMargin

Reference

CodecsTxtLoadOptions Class
CodecsTxtLoadOptions Members
CodecsRasterizeDocumentLoadOptions Class
CodecsRasterizeDocumentLoadOptions Members

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

Leadtools.Codecs Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.