View Single Post
  #6 (permalink)  
Old 02-12-2008, 01:39 PM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Thumbs up Re: Converting image from one format to another in C#

Hi Deepan,
Yes.Here is the code to convert pdf to an image.
Code:
using ( FileStream file = new FileStream( "test.pdf", FileMode.Open, 
                                                      FileAccess.Read ) )
{
   // open the PDF document

   Document document = new Document( new BinaryReader( file ) ); 
  
   // get the first page

   Page page = document.Pages[0];   

   // you must apply a scale to the PDF graphics proportional to the 

   // resolution

   float dpi = 300;
   float scale =  dpi / 72f;
   
   using ( Bitmap bitmap = new Bitmap( (int) ( scale * page.Width ), 
                                       (int) ( scale * page.Height ) ) )
   {
      // wrap a graphics around the bitmap

      Graphics graphics = Graphics.FromImage( bitmap );
  
      // apply the scale that accounts for the resolution

      graphics.ScaleTransform( scale, scale );
      
      // do the actual rendering

      page.Draw( graphics ); 
  
      // save the result as a bmp - could be any format

      bitmap.Save( "test.bmp", ImageFormat.Bmp );
   }
}
Let me know if u have any questions.
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Reply With Quote