←Select platform

GetThumbnail Method

Summary

Gets a thumbnail of a page in the PDF file associated with this PDFDocument.

Syntax

C#
VB
Java
C++
Public Function GetThumbnail( _ 
   ByVal codecs As Leadtools.Codecs.RasterCodecs, _ 
   ByVal pageNumber As Integer, _ 
   ByVal thumbnailWidth As Integer, _ 
   ByVal thumbnailHeight As Integer _ 
) As Leadtools.RasterImage 
public RasterImage getThumbnail(RasterCodecs codecs, int pageNumber, int thumbnailWidth, int thumbnailHeight) 

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#
VB
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:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Controls 
Imports Leadtools.Pdf 
Imports Leadtools.Svg 
Imports Leadtools.WinForms 
 
Public Sub PDFDocumentGetThumbnailExample(ByVal imageList As RasterImageList) 
   Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf") 
 
   ' Open the document 
   Using document As PDFDocument = New PDFDocument(pdfFileName) 
      Using codecs As RasterCodecs = New RasterCodecs() 
         ' For each page... 
         Dim i As Integer = 1 
         Do While i <= document.Pages.Count 
            ' Get the thumbnail of the page 
            Dim image As RasterImage = document.GetThumbnail(codecs, i, 128, 128) 
 
            ' Add it to the image list 
            Dim item As RasterImageListItem = New RasterImageListItem(image, 1, "Page " & i.ToString()) 
            imageList.Items.Add(item) 
            i += 1 
         Loop 
      End Using 
   End Using 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Pdf Assembly