Create PDF Document Thumbnail via PDFViewer

2014-12-31 07:04:02 Written by  support iceblue
Rate this item
(0 votes)

PDF document thumbnails, appearing in the left-hand corner of a PDF reader, provide miniature previews of document pages. The 'Thumbnail View' pane allows you to view page thumbnails of all the pages included in the PDF document and you can simply click on the thumbnail to quickly travel to that page.

This article presents how to create a PDF document thumbnail view in your own .NET PDF viewer via Spire.PDFViewer. Detailed steps are as below:

Step 1: Create a new project in Windows Forms Application.

Step 2: Add Spire.PDFViewer control to VS Toolbox.

Create PDF Document Thumbnail via PDFViewer

Step 3: Design Form1.

  • Add a ToolStrip to Form1. Insert two Buttons, one TextBox and one Label to ToolStrip.
  • Drag PdfDocumentThumbnail and PdfDocumentViewer control from Toolbox to Form1.
  • Set properties of the Buttons, Labels, TextBox, PdfDocumentThumbnail and PdfDocumentViewer as below.

Tools

Properties

As

ToolStripButton1 Name btnOpen
DisplayStyle Image
ToolStripButton2 Name btnThumbnailRatio
DisplayStyle Image
ToolStripLabel1 Name toolStripLabel1
DisplayStyle Text
Text Ratio
ToolStripTextBox Name txtThumbnailRatio
PdfDocumentThumbnail Name pdfDocumentThumbnail1
Dock Fill
PdfDocumentViewer Name pdfDocumentViewer1
Dock Full

Step 4: Set code for btnOpen and btnThumbnailRatio.

1) Create a OpenFileDailog in btnOpen click event which enables you to open a file with correct type.

    private void btnOpen_Click(object sender, EventArgs e)
 {
     OpenFileDialog dialog = new OpenFileDialog();
     dialog.Filter = "PDF document(*.pdf)|*.pdf";
     DialogResult result = dialog.ShowDialog();
     if (result == DialogResult.OK)
     {
         string pdfDocument = dialog.FileName;
         this.pdfDocumentViewer1.LoadFromFile(pdfDocument);
     }

 }

2) Set zoom ratio for thumbnail view mode.

  private void btnThumbnailRatio_Click(object sender, EventArgs e)
  {
      if (this.pdfDocumentViewer1.IsDocumentLoaded)
     {
          int percent = 0;
          bool isNumeric = int.TryParse(this.txtThumbnailRatio.Text, out percent);
          if (isNumeric)
          {
              this.pdfDocumentThumbnail1.ZoomPercent =Math.Abs(percent);
          }
      }
  }

Run this program and open an existing PDF document, you'll get following output:

Create PDF Document Thumbnail via PDFViewer

Additional Info

  • tutorial_title: Create PDF Document Thumbnail
Last modified on Wednesday, 15 September 2021 03:36