C# PDF Thumbnail Image Library
How to get, create, generate, preview thumbnail image from pdf file pages using c# .net
C# Demo Code to enable PDF thumbnail generator viewers in C# class, ASP.NET online pages in .NET Project
In this tutorial, you learn how to use XDoc.PDF thumbnail C# library to
- Create thumbnail images from PDF file
- Create, store thumbnail data into PDF document
- Remove thumbnail data from PDF document
How to create thumbnail image from PDF file using C#
- Advanced C#.NET framework PDF SDK for thumbnail icon generation & creator from PDF document pages in Visual Stutio .NET framework
- Easy .net sdk library for showing, previewing PDF page thumbnails for navigation in both .NET WinForms application and ASP.NET webpage
- Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
- Create, show, display multiple image formats thumbnails for PDF file, such as jpeg, png, gif, bmp, etc
- C# sample code included for quick creating PDF thumbnail viewer in Visual C# .NET class
- Able to control the size of PDF thumbnails in C#.NET console application and ASPX webpage
- Built on .NET framework 2.0 and support Windows 32-bit and 64-bit systems
Page thumbnails are miniature previews of the PDF pages in a document.
In PDF reader applications (such as
EdgePDF ASP.NET PDF Editor), you can use page thumbnails to
navigate quickly to a selected PDF page or to adjust the view of the PDF page.
When you move, copy, or delete a page thumbnail, you move, copy, or delete the corresponding PDF page.
Using XDoc.PDF SDK, you can easily add, insert a new page thumbnail to an existing PDF file.
Create thumbnails from a PDF file, move, delete thumbnails in PDF document.
Create a page thumbnail image using C#
The following C# source code will create a PDF thumbnail, draw and output to a Bitmap object.
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
PDFPage page = (PDFPage)doc.GetPage(0);
// define the size of the thumbnail
Size thumbnailSize = new Size(80, 100);
// create the thumbnail
Bitmap thumbnail = page.ConvertToImage(thumbnailSize);
// do something ...
Add page thumbnails in a PDF document
In a PDF document, each PDF page can have 0 or 1 thumbnail image. If you add a new thumbnail to a PDF page, the new thumbnail image will replace the previous one, if the page has an
existing thumbnail image.
Add thumbnail for single page
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
String outputFilePath = Program.RootPath + "\\" + "1_thumbnail.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
// add thumbnail for the first page
int pageIndex = 0;
PDFThumbnailHandler.UpdateThumbnail(doc, pageIndex);
doc.Save(outputFilePath);
Add thumbnail for multi-pages
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
String outputFilePath = Program.RootPath + "\\" + "1_thumbnail.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
// add thumbnail for multi pages
int[] pageIndexes = new int[3] { 0, 3, 5 };
PDFThumbnailHandler.UpdateThumbnail(doc, pageIndexes);
doc.Save(outputFilePath);
Add thumbnail for all pages
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
String outputFilePath = Program.RootPath + "\\" + "1_thumbnail.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
// add thumbnail for all pages
PDFThumbnailHandler.UpdateThumbnail(doc);
doc.Save(outputFilePath);
Remove page thumbnails in a PDF document
The C# example source code will demo how to remove PDF page thumbnails from a PDF document using C#.
String inputFilePath = Program.RootPath + "\\" + "1_thumbnail.pdf";
String outputFilePath = Program.RootPath + "\\" + "1_no_thumbnail.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
// remove thumbnail for all pages
PDFThumbnailHandler.RemoveThumbnail(doc);
doc.Save(outputFilePath);
C# create Adobe pdf file thumbnail images with specified image size (width, height)
The following C# source code shows how to create PDF page thumbnail images with specified image width and height.
#region generated pdf file thumbnails with specified image size
internal static void generatePdfThumbnailWithSpecifiedSize()
{
String inputFilePath = @"C:\demo.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
for (int i = 0; i < doc.GetPageCount();i++ )
{
BasePage page = doc.GetPage(i);
Bitmap image = page.ConvertToImageFitWidth(100);
}
}
#endregion
C# generate, get pdf thumbnail files for selected PDF pages
The C# code below shows to generate pdf page thumbnail files from selected PDF pages.
#region generated pdf file page's thumbnails with specified image size
internal static void generatePdfPageThumbnailWithSpecifiedSize()
{
String inputFilePath = @"C:\demo.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
int pageIndex = 2;
BasePage page = doc.GetPage(pageIndex);
Bitmap image = page.ConvertToImageFitWidth(100);
}
#endregion
Remove page thumbnails in a PDF document
Using the following C# source code, you can easily remove page thumbnails in a PDF document.
String inputFilePath = Program.RootPath + "\\" + "1_thumbnail.pdf";
String outputFilePath = Program.RootPath + "\\" + "1_no_thumbnail.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
// remove thumbnail for all pages
PDFThumbnailHandler.RemoveThumbnail(doc);
doc.Save(outputFilePath);
Get page thumbnail in a PDF document
If you need read, extract the exsting thumbnail image from a PDF page, you can try the following C# source code.
String inputFilePath = Program.RootPath + "\\" + "1_thumbnail.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
// get thumbnail of the first page if have
int pageIndex = 0;
Bitmap thumbnail = PDFThumbnailHandler.GetThumbnail(doc, pageIndex);
if (thumbnail != null)
{
Console.WriteLine("Page has thumbnail");
Console.WriteLine("Width: " + thumbnail.Width + "; Height: " + thumbnail.Height);
}
else
{
Console.WriteLine("No thumbnail exist");
}