LEADTOOLS PDF (Leadtools.Pdf assembly)
LEAD Technologies, Inc

GetThumbnail Method

Example 





An optional Leadtools.Codecs.RasterCodecs to use when reading the page. If you pass a null reference (Nothing in Visual Basic), then this method will internall create a new Leadtools.Codecs.RasterCodecs object and dispose before it returns.
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). You can use the special value of -1 to donate "last page in the document".
The desired maximum width of the thumbnail image in pixels. Must be greater than 32.
The desired maximum height of the thumbnail image in pixels. Must be greater than 32.
Gets a thumbnail of a page in the PDF file associated with this PDFDocument.
Syntax
public RasterImage GetThumbnail( 
   RasterCodecs codecs,
   int pageNumber,
   int thumbnailWidth,
   int thumbnailHeight
)
'Declaration
 
Public Function GetThumbnail( _
   ByVal codecs As RasterCodecs, _
   ByVal pageNumber As Integer, _
   ByVal thumbnailWidth As Integer, _
   ByVal thumbnailHeight As Integer _
) As RasterImage
'Usage
 
Dim instance As PDFDocument
Dim codecs As RasterCodecs
Dim pageNumber As Integer
Dim thumbnailWidth As Integer
Dim thumbnailHeight As Integer
Dim value As RasterImage
 
value = instance.GetThumbnail(codecs, pageNumber, thumbnailWidth, thumbnailHeight)
public RasterImage GetThumbnail( 
   RasterCodecs codecs,
   int pageNumber,
   int thumbnailWidth,
   int thumbnailHeight
)
 function Leadtools.Pdf.PDFDocument.GetThumbnail( 
   codecs ,
   pageNumber ,
   thumbnailWidth ,
   thumbnailHeight 
)
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 (Nothing in Visual Basic), then this method will internall 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). You can use the special value of -1 to donate "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 (Nothing in Visual Basic) 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.

Example
 
Public Sub PDFDocumentGetThumbnailExample(ByVal imageList As RasterImageList)
      Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "LEAD.pdf")
      ' Open the document
      Using document As New PDFDocument(pdfFileName)

         Using codecs As RasterCodecs = New RasterCodecs()
            ' For each page...
            For i As Integer = 1 To 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 New RasterImageListItem(image, 1, "Page " + i.ToString())
               imageList.Items.Add(item)
            Next
         End Using
      End Using
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void PDFDocumentGetThumbnailExample(RasterImageList imageList)
   {
      string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, @"LEAD.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";
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

PDFDocument Class
PDFDocument Members

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.