←Select platform

CodecsRasterizeDocumentSizeMode Enumeration

Summary
Specifies the transformation to use when converting the logical size specified in the current document rasterization options to the final physical raster image size.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public enum CodecsRasterizeDocumentSizeMode   
typedef NS_ENUM(NSInteger, LTCodecsRasterizeDocumentSizeMode) { 
 LTCodecsRasterizeDocumentSizeModeNone = 0,  
 LTCodecsRasterizeDocumentSizeModeFit = 1,  
 LTCodecsRasterizeDocumentSizeModeFitAlways = 2,  
 LTCodecsRasterizeDocumentSizeModeFitWidth = 3,  
 LTCodecsRasterizeDocumentSizeModeStretch = 4 
}; 
public enum CodecsRasterizeDocumentSizeMode 
public enum class CodecsRasterizeDocumentSizeMode   
class CodecsRasterizeDocumentSizeMode(Enum): 
   None = 0 
   Fit = 1 
   FitAlways = 2 
   FitWidth = 3 
   Stretch = 4 
Members
ValueMemberDescription
0None

Use the original document width and height. No transformation will be performed and CodecsRasterizeDocumentLoadOptions.PageWidth and CodecsRasterizeDocumentLoadOptions.PageHeight are not used.

The final RasterImage will have a width or height value equals to the original document size.

1Fit

Fit the resulting raster image into CodecsRasterizeDocumentLoadOptions.PageWidth and CodecsRasterizeDocumentLoadOptions.PageHeight while maintaining the aspect ratio. If the original document size is smaller than the requested page size, no transformation is performed.

The final RasterImage will have a width or height equal to or less than the requested page width or height but not greater.

2FitAlways

Always fit the resulting raster image into CodecsRasterizeDocumentLoadOptions.PageWidth and CodecsRasterizeDocumentLoadOptions.PageHeight while maintaining the aspect ratio. If the original document size is smaller than the requested page size, then the result image is scaled up.

The final RasterImage will have a width or height equal to the requested page width or height. Not less and not greater.

3FitWidth

Fit the resulting raster image width into CodecsRasterizeDocumentLoadOptions.PageWidth while maintaining the aspect ratio. The image height will be calculated based on the transformation and CodecsRasterizeDocumentLoadOptions.PageHeight is not used.

The final RasterImage will have a width equal to the requested page width. The height depends on the original document height.

4Stretch

The resulting raster image width and height will be exactly equal to CodecsRasterizeDocumentLoadOptions.PageWidth and CodecsRasterizeDocumentLoadOptions.PageHeight. Aspect ratio might be different than the original document.

The final RasterImage will have a width and height equal to the requested page width and height.

Remarks

The CodecsRasterizeDocumentSizeMode enumeration type is used as the value for CodecsRasterizeDocumentLoadOptions.SizeMode property.

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. 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. For more information, refer to CodecsRasterizeDocumentLoadOptions.

You can use the CodecsRasterizeDocumentLoadOptions.SizeMode property to control how to use CodecsRasterizeDocumentLoadOptions.PageWidth and CodecsRasterizeDocumentLoadOptions.PageHeight to control the final raster image size. LEADTOOLS will determine the original document size (a value that can be obtained in CodecsDocumentImageInfo.PageWidth and CodecsDocumentImageInfo.PageHeight and then apply the transformation from this value to determine the final RasterImage width and height.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
 
using Leadtools.ImageProcessing.Core; 
using Leadtools.Pdf; 
 
public void CodecsPdfOptionsExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "PDFSegmentation.pdf"); 
   string destFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "PdfOptions.pdf"); 
   string destFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "PdfOptions.bmp"); 
   CodecsImageInfo info = codecs.GetInformation(srcFileName, true); 
 
   codecs.Options.Pdf.InitialPath = @"C:\MyApp\Bin"; 
 
   info = codecs.GetInformation(srcFileName, true); 
   Debug.WriteLine("Information for: {0}", srcFileName); 
   Debug.WriteLine(string.Format("Document: {0}", info.Document)); // CodecsDocumentImageInfo reference 
   Debug.WriteLine(string.Format("Document: {0}", info.Document.IsDocumentFile)); 
   Debug.WriteLine(string.Format("Document: {0}", info.Document.PageHeight)); 
   Debug.WriteLine(string.Format("Document: {0}", info.Document.PageWidth)); 
   Debug.WriteLine(string.Format("Document: {0}", info.Document.Unit)); 
   Debug.WriteLine(string.Format("Document: {0}", info.IsGray8Alpha)); 
   Debug.WriteLine(string.Format("Palette: {0}", info.GetPalette())); 
 
   // Check if the PDF engine is installed then get the load and save options of the PDF files. 
   if (codecs.Options.Pdf.IsEngineInstalled) 
   { 
      // Resulting image pixel depth. 
      // CodecsPdfOptions & CodecsPdfLoadOptions reference 
      codecs.Options.Pdf.Load.DisplayDepth = 24; 
      codecs.Options.Pdf.Load.GraphicsAlpha = 4; 
      codecs.Options.Pdf.Load.DisableCieColors = false; 
      codecs.Options.Pdf.Load.DisableCropping = false; 
      codecs.Options.Pdf.Load.EnableInterpolate = false; 
      codecs.Options.Pdf.Load.Password = ""; 
 
      // Type of font anti-aliasing to use. 
      codecs.Options.Pdf.Load.TextAlpha = 1; 
      codecs.Options.Pdf.Load.UseLibFonts = true; 
 
      // Horizontal,vertical  display resolution in dots per inch. 
      codecs.Options.RasterizeDocument.Load.XResolution = 150; 
      codecs.Options.RasterizeDocument.Load.YResolution = 150; 
 
      // CodecsRasterizeDocumentOptions & CodecsRasterizeDocumentLoadOptions reference 
      codecs.Options.RasterizeDocument.Load.BottomMargin = 0.1; 
      codecs.Options.RasterizeDocument.Load.LeftMargin = 0.1; 
      codecs.Options.RasterizeDocument.Load.PageHeight = 11; 
      codecs.Options.RasterizeDocument.Load.PageWidth = 8.5; 
      codecs.Options.RasterizeDocument.Load.Resolution = 150; 
      codecs.Options.RasterizeDocument.Load.RightMargin = 1.25; 
      codecs.Options.RasterizeDocument.Load.SizeMode = CodecsRasterizeDocumentSizeMode.None; // CodecsRasterizeDocumentSizeMode Enumeration reference 
      codecs.Options.RasterizeDocument.Load.TopMargin = 1.0; 
      codecs.Options.RasterizeDocument.Load.Unit = CodecsRasterizeDocumentUnit.Pixel; // CodecsRasterizeDocumentUnit Enumeration reference 
 
      using (RasterImage image = codecs.Load(srcFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)) 
      { 
         // Set access rights for the user when he\she opens the file we create 
         // CodecsPdfSaveOptions reference 
         codecs.Options.Pdf.Save.AssembleDocument = true; 
         codecs.Options.Pdf.Save.ExtractText = true; 
         codecs.Options.Pdf.Save.ExtractTextGraphics = true; 
         codecs.Options.Pdf.Save.PrintDocument = false; 
         codecs.Options.Pdf.Save.FillForm = true; 
         codecs.Options.Pdf.Save.ModifyAnnotation = true; 
         codecs.Options.Pdf.Save.ModifyDocument = true; 
         codecs.Options.Pdf.Save.OwnerPassword = "LEAD Technologies"; 
         codecs.Options.Pdf.Save.PrintFaithful = false; 
         codecs.Options.Pdf.Save.TextEncoding = CodecsPdfTextEncoding.Hex; 
         codecs.Options.Pdf.Save.Use128BitEncryption = true; 
         codecs.Options.Pdf.Save.UserPassword = "LEAD"; 
 
         // Set the PDF version to be v1.4 
         codecs.Options.Pdf.Save.Version = CodecsRasterPdfVersion.V14; 
 
         // Save it as linearized (optimized for web view) 
         codecs.Options.Pdf.Save.Linearized = true; 
         codecs.Options.Pdf.Save.LowMemoryUsage = false; 
         codecs.Options.Pdf.Save.SavePdfA = false; 
         codecs.Options.Pdf.Save.SavePdfv13 = false; 
         codecs.Options.Pdf.Save.SavePdfv14 = false; 
         codecs.Options.Pdf.Save.SavePdfv15 = false; 
         codecs.Options.Pdf.Save.SavePdfv16 = false; 
         codecs.Options.Pdf.Save.SavePdfv17 = false; 
         codecs.Options.Pdf.Save.UseImageResolution = true; 
 
         // Save the image back as PDF 
         codecs.Save(image, destFileName1, RasterImageFormat.RasPdf, 24); 
      } 
 
      // And load it back before saving it as BMP 
      using (RasterImage image = codecs.Load(destFileName1)) 
      { 
         codecs.Save(image, destFileName2, RasterImageFormat.Bmp, image.BitsPerPixel); 
      } 
   } 
   else 
   { 
      Debug.WriteLine("PDF Engine is not found!"); 
   } 
 
   // Clean up 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
import java.net.URI; 
import java.net.URISyntaxException; 
import java.nio.file.Paths; 
 
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.codecs.*; 
import leadtools.imageprocessing.core.MinMaxBitsCommand; 
 
 
public void codecsPdfOptionsExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   RasterCodecs codecs = new RasterCodecs(); 
   String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "PDFSegmentation.pdf"); 
   String destFileName1 = combine(LEAD_VARS_IMAGES_DIR, "PdfOptions.pdf"); 
   String destFileName2 = combine(LEAD_VARS_IMAGES_DIR, "PdfOptions.bmp"); 
   CodecsImageInfo info = codecs.getInformation(srcFileName, true); 
   codecs.getOptions().getPdf().setInitialPath("C:\\MyApp\\Bin"); 
   info = codecs.getInformation(srcFileName, true); 
   System.out.println("Information for: " + srcFileName); 
   System.out.println("Document: " + info.getDocument()); // CodecsDocumentImageInfo reference 
   System.out.println("Document: " + info.getDocument().isDocumentFile()); 
   System.out.println("Document: " + info.getDocument().getPageHeight()); 
   System.out.println("Document: " + info.getDocument().getPageWidth()); 
   System.out.println("Document: " + info.getDocument().getUnit()); 
   System.out.println("Document: " + info.isGray8Alpha()); 
   System.out.println("Palette: " + info.getPalette()); 
 
   // Check if the PDF engine is installed then get the load and save options of 
   // the PDF files. 
   if (codecs.getOptions().getPdf().getInitialPath() != null) { 
      // Resulting image pixel depth. 
      // CodecsPdfOptions & CodecsPdfLoadOptions reference 
      codecs.getOptions().getPdf().getLoad().setDisplayDepth(24); 
      codecs.getOptions().getPdf().getLoad().setGraphicsAlpha(4); 
      codecs.getOptions().getPdf().getLoad().setDisableCieColors(false); 
      codecs.getOptions().getPdf().getLoad().setDisableCropping(false); 
      codecs.getOptions().getPdf().getLoad().setEnableInterpolate(false); 
      codecs.getOptions().getPdf().getLoad().setPassword(""); 
 
      // Type of font anti-aliasing to use. 
      codecs.getOptions().getPdf().getLoad().setTextAlpha(1); 
      codecs.getOptions().getPdf().getLoad().setUseLibFonts(true); 
 
      // Horizontal,vertical display resolution in dots per inch. 
      codecs.getOptions().getRasterizeDocument().getLoad().setXResolution(150); 
      codecs.getOptions().getRasterizeDocument().getLoad().setYResolution(150); 
 
      // CodecsRasterizeDocumentOptions & CodecsRasterizeDocumentLoadOptions reference 
      codecs.getOptions().getRasterizeDocument().getLoad().setBottomMargin(0.1); 
      codecs.getOptions().getRasterizeDocument().getLoad().setLeftMargin(0.1); 
      codecs.getOptions().getRasterizeDocument().getLoad().setPageHeight(11); 
      codecs.getOptions().getRasterizeDocument().getLoad().setPageWidth(8.5); 
      codecs.getOptions().getRasterizeDocument().getLoad().setResolution(150); 
      codecs.getOptions().getRasterizeDocument().getLoad().setRightMargin(1.25); 
      codecs.getOptions().getRasterizeDocument().getLoad().setSizeMode(CodecsRasterizeDocumentSizeMode.NONE); // CodecsRasterizeDocumentSizeMode 
                                                                                                              // Enumeration 
                                                                                                              // reference 
      codecs.getOptions().getRasterizeDocument().getLoad().setTopMargin(1.0); 
      codecs.getOptions().getRasterizeDocument().getLoad().setUnit(CodecsRasterizeDocumentUnit.PIXEL); // CodecsRasterizeDocumentUnit 
                                                                                                       // Enumeration 
                                                                                                       // reference 
 
      RasterImage image = codecs.load(srcFileName, 0, CodecsLoadByteOrder.BGR_OR_GRAY, 1, 1); 
 
      // Set access rights for the user when he\she opens the file we create 
      // CodecsPdfSaveOptions reference 
      codecs.getOptions().getPdf().getSave().setAssembleDocument(true); 
      codecs.getOptions().getPdf().getSave().setExtractText(true); 
      codecs.getOptions().getPdf().getSave().setExtractTextGraphics(true); 
      codecs.getOptions().getPdf().getSave().setPrintDocument(false); 
      codecs.getOptions().getPdf().getSave().setFillForm(true); 
      codecs.getOptions().getPdf().getSave().setModifyAnnotation(true); 
      codecs.getOptions().getPdf().getSave().setModifyDocument(true); 
      codecs.getOptions().getPdf().getSave().setOwnerPassword("LEAD Technologies"); 
      codecs.getOptions().getPdf().getSave().setPrintFaithful(false); 
      codecs.getOptions().getPdf().getSave().setTextEncoding(CodecsPdfTextEncoding.HEX); 
      codecs.getOptions().getPdf().getSave().setUse128BitEncryption(true); 
      codecs.getOptions().getPdf().getSave().setUserPassword("LEAD"); 
 
      // Set the PDF version to be v1.4 
      codecs.getOptions().getPdf().getSave().setVersion(CodecsRasterPdfVersion.V14); 
 
      // Save it as linearized (optimized for web view) 
      codecs.getOptions().getPdf().getSave().setLinearized(true); 
      codecs.getOptions().getPdf().getSave().setLowMemoryUsage(false); 
      codecs.getOptions().getPdf().getSave().setSavePdfA(false); 
      codecs.getOptions().getPdf().getSave().setSavePdfv13(false); 
      codecs.getOptions().getPdf().getSave().setSavePdfv14(false); 
      codecs.getOptions().getPdf().getSave().setSavePdfv15(false); 
      codecs.getOptions().getPdf().getSave().setSavePdfv16(false); 
      codecs.getOptions().getPdf().getSave().setSavePdfv17(false); 
      codecs.getOptions().getPdf().getSave().setUseImageResolution(true); 
 
      // Save the image back as PDF 
      codecs.save(image, destFileName1, RasterImageFormat.PDF_LEAD_MRC, 24); 
      image = null; 
 
      // And load it back before saving it as BMP 
      image = codecs.load(destFileName1); 
      codecs.save(image, destFileName2, RasterImageFormat.BMP, image.getBitsPerPixel()); 
 
      assertTrue("File unsuccessfully saved to " + destFileName2, (new File(destFileName2)).exists()); 
      System.out.printf("File successfully saved to %s%n", destFileName2); 
 
      image = null; 
   } else 
      System.out.println("PDF Engine is not found!"); 
 
   // Clean up 
   codecs.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.Codecs Assembly

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