How to convert PDF document into bitmap.

            using Apitron.PDF.Rasterizer;
            using Apitron.PDF.Rasterizer.Configuration;
            ...
            // open and load the file
            using (FileStream fs = new FileStream(@"..\..\..\Documents\testfile.pdf", FileMode.Open))
            {
                // this object represents a PDF document
                Document document = new Document(fs);             

                // process and save pages one by one
                for (int i = 0; i < document.Pages.Count; i++)
                {
                    Page currentPage = document.Pages[i];

                    // we use original page's width and height for image as well as default rendering settings
                    using (Bitmap bitmap = currentPage.Render((int)currentPage.Width, (int)currentPage.Height, new RenderingSettings()))
                    {
                        bitmap.Save(string.Format("{0}.bmp", i), ImageFormat.Bmp);
                    }
                }
            }
        

Default page's Height and Width


                    // the original page's width and height will be used by default for image as well as default rendering settings
                    using (Bitmap bitmap = currentPage.Render(new RenderingSettings()))
                    {
                        bitmap.Save(string.Format("{0}.bmp", i), ImageFormat.Bmp);
                    }
        
          

Use resolution


                    // By default the resolution of the PDF page is set to 72 dpi so if you render the page using its original size you get this resolution. 
                    // we use default rendering settings and double resolution
                    using (Bitmap bitmap = currentPage.Render(new Resolution(144, 144), new RenderingSettings()))
                    {
                        bitmap.Save(string.Format("{0}.png", i), ImageFormat.Png);
                    }      
          

Back to List