←Select platform

RasterCodecsTemplate Property

Summary

Global template used when loading and saving raster and SVG images.

Syntax
C#
C++/CLI
Java
Python
public static RasterCodecs RasterCodecsTemplate { get; set; } 
public:  
   static property RasterCodecs^ RasterCodecsTemplate 
   { 
      RasterCodecs^ get() 
      void set(RasterCodecs^ value) 
   } 
public static RasterCodecs getRasterCodecsTemplate() 
public void sasterCodecs getRasterCodecsTemplate(static value) 
RasterCodecsTemplate # get and set (DocumentFactory) 

Property Value

The global RasterCodecs template to use when loading and saving raster and SVG images. The default value is a RasterCodecs object with the following values:

Property Value
CodecsRasterizeDocumentLoadOptions.Resolution DefaultDocumentResolution (default value is 300)
CodecsLoadOptions.Resolution DefaultRasterResolution (default value is 96)
CodecsVectorLoadOptions.ViewWidth and ViewHeight 1000 by 1000
CodecsPdfLoadOptions.HideAnnotations true
CodecsLoadOptions.AutoFixImageResolution true
CodecsJpegSaveOptions.QualityFactor 40
Remarks

The RasterCodecs class is used throughout the Document library to load and save RasterImage and SvgDocument objects. This class contain various options to control how the data is loaded and processed. For example, one option sets which resolution (DPI) to use when rasterizing a text-based PDF file.

When a new LEADDocument object is created by this factory, a new RasterCodecs object is created and set in RasterCodecs, which is then checked and if it is not null, then the options are copied from and set to LEADDocument.RasterCodecs using CodecsOptions.Clone. This way, the library guarantees that the same global options set by the user in RasterCodecsTemplate are used throughout the application.

The Document library is thread-safe, whereas a single RasterCodecs object is not and so cannot be used by multiple threads at the same time. Therefore, the library will internally create instances of RasterCodecs and dispose of them as needed (for example, when calling DocumentPage.GetImage, to get the raster image representation of a page).

Whenever this happens, the library will copy the options from LEADDocument.RasterCodecs into the options of the temporarily created RasterCodecs object using CodecsOptions.Clone. This way, the library guarantees that the same global options set by the user in the RasterCodecsTemplate are used throughout the application if needed, but still the options can be changed for each LEADDocument individually.

To modify this property, change any of the options to be used by subsequent LEADDocument objects. For instance, the following sample code will load PDF files with embedded annotations burned into the raster or SVG image of the pages:

C#
// By default, the document factory is designed to hide the annotations of a PDF file and instead load them 
// as a live LEADTOOLS annotations file. 
// This code changes this behavior and instead burns the annotations on the pages themselves 
DocumentFactory.RasterCodecsTemplate.Options.Pdf.Load.HideAnnotations = false; 
var loadDocumentOptions = new LoadDocumentOptions(); 
// Do not load any embedded annotations 
loadDocumentOptions.LoadEmbeddedAnnotations = false; 
// Load the document 
LEADDocument document = DocumentFactory.LoadFromFile("path-to-pdf-with-embedded-annotations.pdf", loadDocumentOptions); 
// Set it in the viewer 
documentViewer.SetDocument(document); 
// Set it in the viewer 
documentViewer.SetDocument(document); 
Example

This example shows how to use the RasterCodecsTemplate to change the resolution used when loading document files.

C#
Java
using Leadtools; 
using Leadtools.Caching; 
using Leadtools.Document; 
 
 
public void DocumentFactoryRasterCodecsTemplateExample() 
{ 
   DocumentFactory.RasterCodecsTemplate.Options.RasterizeDocument.Load.XResolution = 100; 
   DocumentFactory.RasterCodecsTemplate.Options.RasterizeDocument.Load.YResolution = 100; 
 
   var options = new LoadDocumentOptions(); 
   using (var document = DocumentFactory.LoadFromFile(Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf"), options)) 
   { 
      foreach (var page in document.Pages) 
      { 
         Console.WriteLine("Page (" + page.PageNumber + ") - Resolution: " + page.Resolution); 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.IOException; 
import java.io.InputStream; 
import java.net.URI; 
import java.net.URISyntaxException; 
import java.util.Calendar; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.caching.*; 
import leadtools.document.*; 
 
 
public void documentFactoryRasterCodecsTemplateExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   DocumentFactory.getRasterCodecsTemplate().getOptions().getRasterizeDocument().getLoad().setXResolution(100); 
   DocumentFactory.getRasterCodecsTemplate().getOptions().getRasterizeDocument().getLoad().setYResolution(100); 
 
   LoadDocumentOptions options = new LoadDocumentOptions(); 
   LEADDocument document = DocumentFactory.loadFromFile(combine(LEAD_VARS_IMAGES_DIR, "Leadtools.pdf"), options); 
   assertTrue(document != null); 
 
   for (DocumentPage page : document.getPages()) { 
      assertTrue(page.getResolution() == 100); 
      System.out.println("Document created successfully"); 
      System.out.println("Page (" + page.getPageNumber() + ") - Resolution: " + page.getResolution()); 
   } 
   document.dispose(); 
} 
Requirements

Target Platforms

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

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