Let’s convert a cover page from a PDF into thumbnail PNG image with size of 100 x 100 pixels using C#:
1. Download the free trial version of the “SautinSoft.PdfFocus.dll”
2. Create a new project in Visual Studio and add a reference to the “SautinSoft.PdfFocus.dll”
3. This is a sample code in C#:
string pathToPdf = @"c:\Book.pdf";
string pathToStoreImages = @"c:\Images\";
SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
f.OpenPdf(
if (f.PageCount > 0)
{
System.Drawing.Image img = null;
f.ImageOptions.Dpi = 72;
float thumbnailWidthPx = 100;
float thumbnailHeightPx = 100;
int page = 1; //cover page
//1. Convert PDF into same size image
img = f.ToDrawingImage(
//Save original image
img.Save(
//2. Make thumnail and save it as png
Bitmap bmpThumnail = new Bitmap((int)
Graphics e = Graphics.FromImage(
float koeffW = (float)img.Width / thumbnailWidthPx;
float koeffH = (float)img.Height / thumbnailHeightPx;
float maxKoeff = (koeffW > koeffH) ? koeffW : koeffH;
Rectangle rectSource = new Rectangle(0, 0, img.Width, img.Height);
int x = 0;
int y = 0;
if (koeffW > koeffH)
y = ((int)thumbnailHeightPx - (int)(img.Height / maxKoeff)) / 2;
else
x = ((int)thumbnailWidthPx - (int)(img.Width / maxKoeff)) / 2;
Rectangle rectDest = new Rectangle(x, y, (int)(img.Width / maxKoeff), (int)(img.Height / maxKoeff));
e.DrawImage(
bmpThumnail.Save(
}
Resume:
This code uses the SautinSoft’s library – PDF Focus .Net which can convert any types of PDF documents to Word, RTF, Text documents and Images (PNG, JPG, Multipage-TIFF etc).
To launch this code, please download the free trial version of the “SautinSoft.PdfFocus.dll”
http://www.sautinsoft.com/
Or here: http://www.sautinsoft.com/
Need any assistance? Ask us online at http://www.sautinsoft.com
Max Sautin
Photo:
http://www.prlog.org/



