1. Latest News
  2. Submit Press Release
  1. PR Home
  2. Latest News
  3. Feeds
  4. Alerts
  5. Submit Free Press Release
  6. Journalist Account
  7. PRNewswire Distribution
Sautin Software Logo

How to convert a PDF document into thumbnail image with specified dimensions in C# and VB.Net

Sometimes is necessary to convert a page from PDF document into image (png, jpg, bmp, doesn't really matter to show it in a browser). Let us say, if we're creating an e-library website. This e-library stores a lot of e-books in a PDF format.

 
 
How to convert PDF into thumbnail image
How to convert PDF into thumbnail image
PRLog - Aug. 2, 2012 - Actually a lot of browsers can show a PDF document with help of Acrobat Reader plugin, but this will not work fast when you want to show let’s say cover pages from 50 PDFs. Much faster solution is convert a cover page from each PDF document into image and show it a browser.

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” from here: http://www.sautinsoft.com/products/pdf-focus/index.php

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(pathToPdf);

           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(page);
               //Save original image
               img.Save(pathToStoreImages + "Page" + page.ToString() + ".png", System.Drawing.Imaging.ImageFormat.Png);

               //2. Make thumnail and save it as png
               Bitmap bmpThumnail = new Bitmap((int)thumbnailWidthPx, (int)thumbnailHeightPx);
               Graphics e = Graphics.FromImage(bmpThumnail);
               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(img, rectDest, rectSource, GraphicsUnit.Pixel);
               bmpThumnail.Save(pathToStoreImages + "Thumbnail" + page.ToString() + ".png", System.Drawing.Imaging.ImageFormat.Png);

           }


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” from here:

http://www.sautinsoft.com/products/pdf-focus/index.php

Or here: http://www.sautinsoft.com/components/pdf_focus_net.zip.

Need any assistance? Ask us online at http://www.sautinsoft.com

Max Sautin

Photo:
http://www.prlog.org/11940326/1

--- End ---

Click to Share

Contact Email:
***@sautinsoft.com Email Verified
Source:SautinSoft
Country:Russian Federation
Industry:vb.net
Tags:PDF, word, images, jpg, png
Shortcut:prlog.org/11940326
Disclaimer:   Issuers of the press releases are solely responsible for the content of their press releases. PRLog can't be held liable for the content posted by others.   Report Abuse

Latest Press Releases By “

More...

Trending News...



  1. SiteMap
  2. Privacy Policy
  3. Terms of Service
  4. Copyright Notice
  5. About
  6. Advertise
Like PRLog?
9K2K1K
Click to Share