Visual Basic (Declaration) | |
---|---|
Public Class CodecsRasterizeDocumentLoadOptions |
Visual Basic (Usage) | Copy Code |
---|---|
|
C# | |
---|---|
public class CodecsRasterizeDocumentLoadOptions |
C++/CLI | |
---|---|
public ref class CodecsRasterizeDocumentLoadOptions |
This example will load a PDF document using different rasterize document options and show its effect on the result raster image width, height and resolution.
Visual Basic | Copy Code |
---|---|
Public Sub RasterizeDocumentExample() |
C# | Copy Code |
---|---|
public void RasterizeDocumentExample() |
LEADTOOLS provides support for loading a document as a raster image. Documents formats such as PDF, XPS, XLS, RTF and Text do not contain physical width, height or resolution. 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 of converting a document to a raster image. To check if a certain file on disk (or in a .NET stream) contains a document file rather than a regular raster image, call the RasterCodecs.GetInformation and check the CodecsDocumentImageInfo.IsDocumentFile property. Here is a code snippet:
CodecsImageInfo imageInfo = rasterCodecsInstance.GetInformation(fileName, true);
if(imageInfo.Document.IsDocumentFile)
{
// A document file (PDF, XPS, rtc), 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 value. For example, the following code snippet will instruct LEADTOOLS to fit any document files into 8.5 by 11 inches at 300 paper size. Every document file loaded with the RasterCodecs.Load 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;
// Enable rasterization
rasterDocumentLoadOptions.Enabled = true;
// 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 |
---|---|
Enabled | Enable or disable using the current CodecsRasterizeDocumentLoadOptions properties when loading document files. You must set the value of this property to true before using the other members of this class. |
PageWidth and PageHeight | The result page width and height (in Unit). The value of the result 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 from the left, top, right and bottom in Unit. Currently, only RTF and TXT documents support margins. |
Unit | The units to use for the PageWidth, PageHeight, LeftMargin, TopMargin, RightMargin and BottomMargin values. |
XResolution and YResolution | The resolution to use when rasterization the document files. A value of 0 means using the current screen resolution (usually 96). The resolution controls the pixel density of the result raster image. For example, if you specify 8.5 by 11 inches page width and height and a resolution of 96, the result 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 1005 by 11 inch document, this results in a raster image size if P:Leadtools.Codecs.CodecsRasterizeDocumentLoadOptions.SizeMode Refer to T:Leadtools.Codecs.CodecsRasterizeDocumentSizeMode |
The value of CodecsRasterizeDocumentLoadOptions.Enabled:P:Leadtools.Codecs.CodecsRasterizeDocumentLoadOptions.Enabled This is done for backward compatibilty and means the current T:Leadtools.Codecs.CodecsRasterizeDocumentLoadOptions A convenient way to do that is after instantiating the T:Leadtools.Codecs.RasterCodecs object you will be using in your codeCodecsRasterizeDocumentLoadOptions.Enabled:P:Leadtools.Codecs.CodecsRasterizeDocumentLoadOptions.Enabled% to true in the next version so it is recommended you start porting your code to use the new options.
System.Object
Leadtools.Codecs.CodecsRasterizeDocumentLoadOptions
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family