←Select platform

GetThumbnail Method

Summary
Gets a thumbnail of a page in the PDF file associated with this PDFDocument.
Syntax
C#
C++/CLI
Java
Python

Parameters

codecs
An optional Leadtools.Codecs.RasterCodecs to use when reading the page. If you pass a null reference, then this method will internally create a new Leadtools.Codecs.RasterCodecs object and dispose before it returns.

pageNumber
The 1-based page number. Must be greater than or equal to 1 and less than or equal to the total number of pages in the document (Pages.Count). Use the special value of -1 to represent the last page in the document.

thumbnailWidth
The desired maximum width of the thumbnail image in pixels. Must be greater than 32.

thumbnailHeight
The desired maximum height of the thumbnail image in pixels. Must be greater than 32.

Return Value

A new Leadtools.RasterImage that is the thumbnail image.

Remarks

If the page width and height is less than  thumbnailWidth and  thumbnailHeight, then this method returns an in the original size.

If the page width or height is greater than  thumbnailWidth and  thumbnailHeight, then this method will return the biggest thumbnail it can fit into the dimensions specified by  thumbnailWidth and  thumbnailHeight, keeping the original image aspect ratio.

The result image will always have 24 bits per pixel and a resolution of 96 by 96 regardless of the value of Resolution set in this PDFDocument and will never return a thumbnail bigger than the original page size in pixels.

This method uses Leadtools.RasterImage.CalculatePaintModeRectangle(System.Int32,System.Int32,Leadtools.LeadRect,Leadtools.RasterPaintSizeMode,Leadtools.RasterPaintAlignMode,Leadtools.RasterPaintAlignMode) to calculate the thumbnail size and then the RasterCodecs.Load resize method to load the thumbnail with RasterSizeFlags.Resample will be used as the flags parameter.

Since a Leadtools.Codecs.RasterCodecs object is required by this method, you can either pass one through the  codecs parameter and the method will use this object to load the page. This is helpful if you need to change the default Leadtools.Codecs.RasterCodecs load options or subscribe to any of the events that will occur during loading. If none of that is required, you can simply pass null for the  codecs parameter and this method will internally create, use and dispose a temporary Leadtools.Codecs.RasterCodecs object.

To get a render of the full size of any page in a PDF document, use GetPageImage and GetPageSvg(RasterCodecs,Int32,CodecsLoadSvgOptions) to get an SVG document of the page.

Example

This example will get thumbnails of a PDF file and add them to a LEADTOOLS Raster Image List control.

C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Controls; 
using Leadtools.Pdf; 
using Leadtools.Svg; 
using Leadtools.WinForms; 
 
 
public void PDFDocumentGetThumbnailExample(RasterImageList imageList) 
{ 
   string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, @"Leadtools.pdf"); 
 
   // Open the document 
   using (PDFDocument document = new PDFDocument(pdfFileName)) 
   { 
      using (RasterCodecs codecs = new RasterCodecs()) 
      { 
         // For each page... 
         for (int i = 1; i <= document.Pages.Count; i++) 
         { 
            // Get the thumbnail of the page 
            RasterImage image = document.GetThumbnail(codecs, i, 128, 128); 
 
            // Add it to the image list 
            RasterImageListItem item = new RasterImageListItem(image, 1, "Page " + i.ToString()); 
            imageList.Items.Add(item); 
         } 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.BufferedWriter; 
import java.io.Console; 
import java.io.File; 
import java.io.FileWriter; 
import java.io.IOException; 
import java.io.OutputStream; 
import java.io.OutputStreamWriter; 
import java.nio.Buffer; 
import java.nio.file.Files; 
import java.nio.file.Path; 
import java.nio.file.Paths; 
import java.nio.file.StandardOpenOption; 
import java.sql.Date; 
import java.text.SimpleDateFormat; 
import java.time.LocalDateTime; 
import java.util.ArrayList; 
import java.util.List; 
 
import javax.xml.validation.Schema; 
 
import org.apache.lucene.store.Directory; 
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.barcode.*; 
import leadtools.codecs.*; 
import leadtools.pdf.*; 
import leadtools.svg.*; 
 
 
public void pdfDocumentGetThumbnailExample() { 
   String LEAD_VARS_ImagesDir = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String pdfFileName = combine(LEAD_VARS_ImagesDir, "Leadtools.pdf"); 
   String outFileName = combine(LEAD_VARS_ImagesDir, "pdfThumbnail.tif"); 
 
   PDFDocument document = new PDFDocument(pdfFileName); 
   RasterCodecs codecs = new RasterCodecs(); 
   RasterImage image = document.getThumbnail(codecs, 1, 128, 128); 
   codecs.save(image, outFileName, RasterImageFormat.TIF, 0); 
   assertTrue(new File(outFileName).exists()); 
} 
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.Pdf Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.