Create thumbnails from PDFs in C#
This guide explains how to create an image from a PDF document’s page. For example, you can use the created image as a thumbnail preview for the PDF document.
Download sampleTo create an image from a PDF document’s page, follow these steps:
- Create a
GdPicturePDFobject and aGdPictureImagingobject. - Load the source document by passing its path to the
LoadFromFilemethod of theGdPicturePDFobject. - Select the page from which to create an image with the
SelectPagemethod of theGdPicturePDFobject. - Render the selected page to an image with the
RenderPageToGdPictureImageExmethod of theGdPicturePDFobject. This method takes the following parameters:- The dots-per-inch (DPI) resolution of the image.
- A Boolean value that defines whether to include form fields and annotations in the image.
- Save the image to a file with the
SaveAsPNGmethod of theGdPictureImagingobject. - Release unnecessary resources.
The following example creates a thumbnail-sized PNG image from a PDF document’s first page. At 24 DPI, an A4 page renders to about 198×281 pixels:
Register the SDK license before running SDK operations. For setup details, refer to the getting started with .NET SDK guide.
using GdPicture14;
LicenseManager license = new LicenseManager();license.RegisterKEY("");using GdPicturePDF gdpicturePDF = new GdPicturePDF();using GdPictureImaging gdpictureImaging = new GdPictureImaging();// Load the source document.gdpicturePDF.LoadFromFile(@"input.pdf");// Select the first page.gdpicturePDF.SelectPage(1);// Render the selected page to an image.int imageId = gdpicturePDF.RenderPageToGdPictureImageEx(24, true);// Save the image to a file.gdpictureImaging.SaveAsPNG(imageId, @"output.png");// Release unnecessary resources.gdpictureImaging.ReleaseGdPictureImage(imageId);Register the SDK license before running SDK operations. For setup details, refer to the getting started with .NET SDK guide.
Imports GdPicture14
Dim license As LicenseManager = New LicenseManager()license.RegisterKEY("")Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()Using gdpictureImaging As GdPictureImaging = New GdPictureImaging() ' Load the source document. gdpicturePDF.LoadFromFile("input.pdf") ' Select the first page. gdpicturePDF.SelectPage(1) ' Render the selected page to an image. Dim imageId As Integer = gdpicturePDF.RenderPageToGdPictureImageEx(24, True) ' Save the image to a file. gdpictureImaging.SaveAsPNG(imageId, "output.png") ' Release unnecessary resources. gdpictureImaging.ReleaseGdPictureImage(imageId)End UsingEnd UsingRelated topics