Read the complete article on how to generate thumbnails for PDF file in C# .NET: https://blog.aspose.com/2022/05/16/generate-thumbnails-for-pdf-files-in-csharp/
Last active
January 12, 2024 13:07
Generate Thumbnails for PDF Files in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open document | |
Document pdfDocument = new Document("file.pdf"); | |
// Loop through pages | |
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++) | |
{ | |
// Create stream for each image | |
using (FileStream imageStream = new FileStream("Thumbanils_" + pageCount + ".jpg", FileMode.Create)) | |
{ | |
// Create Resolution object | |
Resolution resolution = new Resolution(300); | |
// Create an instance of JpegDevice and set height, width, resolution, and quality of image | |
JpegDevice jpegDevice = new JpegDevice(45, 59, resolution, 100); | |
// Convert a particular page and save the image to stream | |
jpegDevice.Process(pdfDocument.Pages[pageCount], imageStream); | |
// Close stream | |
imageStream.Close(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open document | |
Document pdfDocument = new Document("file.pdf"); | |
int pageIndex = 0; | |
// Get page of desired index from collection | |
var page = pdfDocument.Pages[pageIndex]; | |
// Create stream for image file | |
using (FileStream imageStream = new FileStream("Thumbanils_" + page.Number + ".jpg", FileMode.Create)) | |
{ | |
// Create Resolution object | |
Resolution resolution = new Resolution(300); | |
// Create an instance of JpegDevice and set height, width, resolution, and quality of image | |
JpegDevice jpegDevice = new JpegDevice(45, 59, resolution, 100); | |
// Convert a particular page and save the image to stream | |
jpegDevice.Process(page, imageStream); | |
// Close stream | |
imageStream.Close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment