←Select platform

CodecsRasterizeDocumentLoadOptions Class


Contains set options for loading a document file as a raster image (rasterization).

public class CodecsRasterizeDocumentLoadOptions 
Public Class CodecsRasterizeDocumentLoadOptions  
@interface LTCodecsRasterizeDocumentLoadOptions : NSObject 
public class CodecsRasterizeDocumentLoadOptions 
public ref class CodecsRasterizeDocumentLoadOptions  


LEADTOOLS provides support for loading a document as a raster image. Document formats such as PDF, XPS, DOCX/DOC, PPTX/PPT, XLSS/XLS, RTF and Text do not contain physical width, height or resolution information. It is up to the loader (in this case, the RasterCodecs object) to specify the transformation from logical coordinates to physical pixels through a process called rasterization.

Rasterization is the process through which a document is converted into a raster image. To check whether a certain file on disk (or in a .NET stream) contains a document file rather than a regular raster image, call the RasterCodecs.GetInformation or RasterCodecs.GetInformationAsync method and check the CodecsDocumentImageInfo.IsDocumentFile property. Here is a code snippet:

CodecsImageInfo imageInfo = rasterCodecsInstance.GetInformation(fileName, true); 
   // A document file (PDF, XPS, DOCX/DOC, PPTX/PPT, XLSS/XLS, etc), show the original document size: 
   Console.WriteLine("Document file, original size is {0} by {1} {2}", 
      imageInfo.Document.PageWidth, imageInfo.Document.PageHeight, imageInfo.Document.Unit); 
   // Your code specific to rasterization based on the original document size goes here 

To rasterize a document file, set the properties of the CodecsRasterizeDocumentLoadOptions to the required values. For example, the following code snippet will instruct LEADTOOLS to fit any document files into 8.5 by 11 inches paper size at 300 dpi resolution. Every document file loaded with the RasterCodecs.Load or RasterCodecs.LoadAsync methods will have width/height of no more than 2550 by 3300 pixels with a resolution of 300 by 300:

CodecsRasterizeDocumentLoadOptions rasterDocumentLoadOptions = rasterCodecsInstance.Options.RasterizeDocument.Load; 
// Set the size mode, we want to fit 
rasterDocumentLoadOptions.SizeMode = CodecsRasterizeDocumentSizeMode.Fit; 
// Set the page size 
rasterDocumentLoadOptions.PageWidth = 8.5; 
rasterDocumentLoadOptions.PageHeight = 11; 
rasterDocumentLoadOptions.Unit = CodecsRasterizeDocumentUnit.Inch; 
// And the resolution 
rasterDocumentLoadOptions.XResolution = 300; 
rasterDocumentLoadOptions.YResolution = 300; 
// Load the image 
RasterImage image = rasterCodecsInstance.Load(fileName); 
// Show its pixel size, it should be less than or equal to 
// 2550 by 3300 pixels (8.5 * 300 by 11 * 300) 
Console.WriteLine("Loaded image size: {0} by {1} pixels at {2} by {3}", 
image.ImageWidth, image.ImageHeight, image.XResolution, image.YResolution); 

The CodecsRasterizeDocumentLoadOptions class contains the following properties:

Property Description
PageWidth and PageHeight

The resulting page width and height (in Unit). The value of the resulting raster image width and height in pixels depends on the current resolution and size mode values.

LeftMargin, TopMargin, RightMargin and BottomMargin The size of the margins to leave on the left, top, right and bottom margins using Unit as the unit of measure. Currently, only RTF, TXT and documents support margins.

The units to use for the PageWidth, PageHeight, LeftMargin, TopMargin, RightMargin and BottomMargin values.

XResolution, YResolution and Resolution

The resolution to use when rasterizing the document files. A value of 0 means to use the current screen resolution (usually 96). The resolution controls the pixel density of the resulting raster image. For example, if you specify 8.5 by 11 inches page width and height and a resolution of 96, the resulting image will have a pixel width and height of (8.5 * 96 = 816) and (11 * 96 = 1056) pixels. This is suitable for viewing at a 100 percent zoom but when you start zooming in, the image will get pixelated. Pixelation may also occur if you send the raster image to a printer, since printers usually have much higher resolution than a monitor.

If zooming in or high quality printing is a requirement in your code, then a higher resolution value must be specified (for example, 300 by 300). For an 8.5 by 11 inch document, this results in a raster image size of (8.5 * 300 = 2550) and (11 * 300 = 3300) pixels, which is more than suitable for printing or zooming in. Keep in mind that increasing the resolution will increase the memory used to hold the image data. Finding the right balance between pixel density and memory consumption depends upon your application needs.


Controls the transformation used when converting the logical size specified in page width and height to the physical raster image size. Refer to CodecsRasterizeDocumentSizeMode for more information.

Refer to the C# and VB Rasterize Document Demo that ships with your version of LEADTOOLS for an interactive demonstration of CodecsRasterizeDocumentLoadOptions.


For an example, refer to CodecsPdfOptions.  


Target Platforms

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

Leadtools.Codecs Assembly