Gets this page as a raster image at the specified resolution.
public RasterImage GetImage(
int resolution
)
resolution
Resolution to use in dots per inch. If this value is 0, then the current page Resolution value is used.
This page as a RasterImage object.
GetImage and GetImage(resolution) are used to get a raster image representation of this page. All document types support this method and it will always return a value object.
SetImage is used to replace the raster image of the page. IsImageModified is used to as flag that indicates that the image of this page has been replaced by the user.
If this document type supports loading raster images at any resolution (the value of DocumentImages.IsResolutionsSupported is true), then this method will use the resolution parameter instead of the Resolution property when loading the image.
If this document type does not support loading raster images at any resolution (the value of DocumentImages.IsResolutionsSupported is false), then resolution is ignored and the original page Resolution value is used.
This method works as follows (the "item" is a raster image with the specified resolution):
If an item was found in the cache, it is returned right away. This is available if the document was created using the cache system. and LEADDocument.CacheOptions contains DocumentCacheOptions.PageImage.
If this is an original page in the source document file (the value of OriginalPageNumber is not -1), then RasterCodecs is used to load the RasterImage object from the original page.
If this is not an original page in the source document file (the value of OriginalPageNumber is not 1), then a new RasterImage object is created based on the page size and resolution and the default values in DocumentImages.
If this document uses the cache system (LEADDocument.HasCache is true), then the RasterImage object is saved to the cache before it is returned. Next time this method is called, the image will be returned from the cache directly without loading it from the file or creating a new instance.
Note that if SetImage has been previously called with a null object for the image parameter, then this method will return null as well.
In all cases, the returned RasterImage object is not used by this LEADDocument, the user is responsible for deleting it using RasterImage.Dispose after it has been used.
If the value of ImageScale is a value greater than 1, then the result raster image will have a size that is equal to Size / ImageScale.
The LEADTOOLS Document Viewer uses this method to obtain the raster image for the page when the view mode is "Raster Image".
The LEADTOOLS Document Converter uses this method to obtain the raster image for the page when converting using OCR or when adding the overlay image of a page if needed.
Refer to Loading Using LEADTOOLS Document Library for more information.
using Leadtools;
using Leadtools.Caching;
using Leadtools.Document;
public void DocumentExample()
{
var cache = GetCache();
var policy = new CacheItemPolicy();
policy.AbsoluteExpiration = DateTime.Now + new TimeSpan(0, 0, 1);
policy.SlidingExpiration = new TimeSpan(0, 0, 1);
var options = new LoadDocumentOptions();
options.CachePolicy = policy;
options.Cache = cache;
if(options.Cache == null)
{
options.Cache = DocumentFactory.Cache;
}
string documentId = null;
using (var document = DocumentFactory.LoadFromFile(Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf"), options))
{
document.GetDocumentFileName();
document.IsReadOnly = false;
document.AutoDeleteFromCache = false;
// DocumentImages reference
document.Images.DefaultBitsPerPixel = 24;
Console.WriteLine(document.Images.IsResolutionsSupported);
Console.WriteLine(document.Images.IsSvgSupported);
// Check if the document has a stream in memory
if (document.HasStream)
{
// Get the document stream
document.GetDocumentStream();
}
// Indicate whether the document is using the cache or not
Console.WriteLine(document.HasCache);
//Indicate if the document was downloaded
Console.WriteLine(document.IsDownloaded);
// Gets a value that determines whether the document structure is supported
Console.WriteLine(document.IsStructureSupported);
// Output metadata values (DocumentMetadata reference)
Console.WriteLine(document.Metadata.Values.Count);
// Get the Mime type of the document
Console.WriteLine(document.MimeType);
// Parse document structure data (DocumentStructure reference)
foreach(DocumentBookmark bookmark in document.Structure.Bookmarks)
{
bookmark.Title = null;
bookmark.FontStyles = DocumentFontStyles.Normal;
document.Structure.Bookmarks.Add(bookmark);
Console.WriteLine(bookmark.Children);
Console.WriteLine(bookmark.Target);
Console.WriteLine(document.Structure.Bookmarks.Count);
Console.WriteLine(document.Structure.IsParsed);
Console.WriteLine(document.Structure.ParseBookmarks);
}
document.Structure.Parse();
// Get the document URI
Console.WriteLine(document.Uri);
// Get each DocumentPage object (DocumentPage & DocumentPages reference)
foreach (DocumentPage page in document.Pages)
{
// Get the page as a raster image at the specified resolution
page.GetImage(0);
// Get the page as an Svg with specified options
page.GetSvg(null);
// Flip this page horizontally
page.Reverse();
// Use this method to add an array of links for this page
page.SetLinks(null);
page.IsLinksModified = false;
page.Resolution = 0;
page.ViewPerspective = RasterViewPerspective.TopLeft;
page.SetLinks(page.GetLinks());
Console.WriteLine($"Page Number: {page.PageNumber}, Original PageNumber: {page.OriginalPageNumber}, Size of the page: {page.Size}");
}
PrintOutDocumentInfo(document);
documentId = document.DocumentId;
document.SaveToCache();
}
System.Threading.Thread.Sleep(2000);
var loadFromCacheOptions = new LoadFromCacheOptions();
loadFromCacheOptions.Cache = cache;
loadFromCacheOptions.DocumentId = documentId;
using (var document = DocumentFactory.LoadFromCache(loadFromCacheOptions))
{
if (null == document)
{
Console.WriteLine("Cached document was expired and deleted!");
}
}
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}