How to Start Tutorials Troubleshooting Main Operations Convert PDF Read PDF Edit PDF PDF Report Generator Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

C# PDF to Image Converter Library
How to convert PDF page to gif, bitmap images in byte array using C#.net. Free open source examples


Online C# demo source codes for converting PDF page to image. No ghostscript, itextsharp, pdfsharp needed.





In this C# tutorial, you will learn how to convert PDF page to raster image, such as png, jpeg2000, gif, using C# in ASP.NET Core, MVC, Windows application

  • Convert PDF to images with basic image settings in file or byte array
  • Convert PDF to PNG, JPEG2000 image with customized image settings
  • Split PDF into images, one page converted to one image
  • No open source required, such as ghostscript, itextsharp, pdfsharp
  • Support .NET 8, 7, 6, 5, .NET Core 3.1, 2.1 and .NET Framework 4.x, 3.x and 2.x

How to convert PDF to image files using C#

  1. Download XDoc.PDF image conversion C# library
  2. Install C# library to convert Adobe PDF page to png, jpeg2000 images
  3. Step by Step Tutorial








  • Best PDF converter SDK for Visual Studio .NET for converting PDF to image in C#.NET application
  • Free .NET DLLs for converting PDF to images in both .NET WinForms and ASP.NET application
  • An advanced .NET control able to batch convert PDF documents to image formats in C#.NET
  • Support exporting PDF to multiple image forms, including Jpg, Png, Bmp, Gif, Tiff, Bitmap, .NET Graphics, and REImage
  • Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
  • Professional .NET library and Visual C# source code for creating high resolution images from PDF in C#.NET class
  • Create image files including all PDF contents, like watermark and signature in .NET
  • Turn multipage PDF file into single image files respectively in .NET framework
  • Converter control easy to create thumbnails from PDF pages
  • More about PDF converter: c# save docx as pdf, convert txt to pdf c#, convert pdf to tiff c# free, convert image to pdf c#, c# code to save excel file as pdf, convert pdf to word using interop c#.
  • Selection for compressing to multiple image formats
  • Cut and paste any areas in PDF pages to images
  • Supports to resize images in conversion


RasterEdge.com provides C# developers with mature PDF document processing and rendering library SDK. Our XDoc.PDF allows C# developers to perform high performance conversions from PDF document to multiple image forms. Besides raster image Jpeg, images forms like Png, Bmp, Gif, .NET Graphics, and REImage (an intermediate class) are also supported. In the following parts, we provide some examples for these PDF conversions.





Image Formats Supported


With XDoc.PDF for .NET, you can easily convert Adobe PDF pages to any of the following raster image formats:

  • ImageType.BMP
  • ImageType.GIF
  • ImageType.PNG
  • ImageType.JPEG
  • ImageType.JPEG2000
  • ImageType.TIFF






Image Conversion Options in C#


Class ImageOutputOption allows you to apply image option settings during converting PDF pages to raster images in C#.




Bitmap (BMP), Gif, JPEG2000 image options using C#


With XDoc.PDF for .NET, you can easily convert single PDF file or mutliple PDF documents into PNG images. The following png image settings supported in class "ImageOutputOption":


  1. Color: Output png image is Monochrome, Gray, Color.
  2. Zoom: Set zoom value to 2F. Use more pixels to render the page.
  3. Resolution: Set image resolution value in the JPEG file.




PNG image options using C#

Please view PNG image option details at How to convert PDF pages to PNG images in C#.NET.





JPEG image options

Please go to How to convert PDF pages to JPG images in C# for JPG image options.





TIFF image options

Please go to How to convert PDF file to multipage TIFF image in C# for TIFF image options.







C# split PDF document into image files, one PDF page per image file in C# code


The C# code below will show how to split a PDF file into multiple image files with image options applied. One PDF page will produce one image file.



        #region convert single pdf file to image with image settings(file to file)
        internal static void pdf2Image()
        {
            String inputFilePath = @"C:\demo.pdf";
            String outputDirectory = @"C:\output\";
            ImageOutputOption ops = new ImageOutputOption();
            ops.Color = ColorType.Monochrome;
            ops.Resolution = 120;
            PDFDocument doc = new PDFDocument(inputFilePath);
            doc.ConvertToImages(ImageType.PNG, ops, outputDirectory, "fileName");
        }
        #endregion

        #region convert single pdf file to image with image settings(Stream to Stream)
        internal static void pdfStream2ImageStream()
        {
            String inputFilePath = @"C:\demo.pdf";
            byte[] arr = File.ReadAllBytes(inputFilePath);
            MemoryStream inputStream = new MemoryStream(arr);
            PDFDocument doc = new PDFDocument(inputStream);

            List<Stream> outputStreams = new List<Stream>();
            for (int i = 0; i < doc.GetPageCount();i++ )
            {
                outputStreams.Add(new MemoryStream());
            }

            ImageOutputOption ops = new ImageOutputOption();
            ops.Color = ColorType.Monochrome;
            ops.Resolution = 120;
            doc.ConvertToImages(ImageType.PNG, ops, outputStreams.ToArray());
        }
        #endregion






Convert the first page of PDF file to image to preview using C#.NET


The steps and C# code below will explain how to convert the first page of a PDF file to preview in C#.

  1. Create a new ImageOutputOption object to preview the first page of PDF file
  2. Set image type to Bitmap ImageType.BMP
  3. Set image color to ColorType.Color
  4. Set PDF page zoom is 0.25F
  5. Set image resolution to 300 dpi.
  6. Create a PDFDocument object with PDF file loaded
  7. Get the first page object PDFPage of the PDF document
  8. Use the method PDFPage.ConvertToImage() to convert the first page of PDF file to bitmap image file



            String inputFilePath = @"W:\Projects\Test-Files\file1.pdf";
            String outputFilePath = @"W:\Projects\Test-Output\RasterEdge.com\pdf-convert-pdf-to-bmp-preview.bmp";

            ImageOutputOption options = new ImageOutputOption();
            options.Type = ImageType.BMP;

            //  Output image is Monochrome, Gray, Color.
            options.Color = ColorType.Color;
            //  Set zoom value to 2F. Use more pixels to render the page.
            options.Zoom = 0.25F;
            //  Set resolution value in the bitmap file to 96 dpi.
            options.Resolution = 300;

            //  Open file and get the target page
            PDFDocument doc = new PDFDocument(inputFilePath);
            PDFPage page = (PDFPage)doc.GetPage(0);

            //  Convert page to a Bitmap (.bmp) image
            page.ConvertToImage(options, outputFilePath);




C# convert single pdf file to jpeg2000 with image options


        #region convert single pdf file to Jpeg2000 with image options
        internal static void pdf2Jpeg2000Image()
        {
            String inputFilePath = @"C:\demo.pdf";
            String outputDirectory = @"C:\output\";
            ImageOutputOption ops = new ImageOutputOption();
            ops.Color = ColorType.Monochrome;
            ops.Resolution = 120;
            ops.Zoom = 1.5f;
            //To set more settings.....

            PDFDocument doc = new PDFDocument(inputFilePath);
            doc.ConvertToImages(ImageType.JPEG2000, ops, outputDirectory, "fileName");
        }
        #endregion




C# convert two or multiple pdf files to image (batch convert)


        #region convert two or multiple pdf files to image(batch files and single tread)
        internal static void pdfFilesToImage()
        {
            String inputDirectory = @"C:\input\";
            String outputDirectory = @"C:\output\";
            String[] files = Directory.GetFiles(inputDirectory, "*.pdf");
            foreach (String filePath in files)
            {
                int startIdx = filePath.LastIndexOf("\\");
                int endIdx = filePath.LastIndexOf(".");
                String docName = filePath.Substring(startIdx + 1, endIdx - startIdx - 1);
                PDFDocument doc = new PDFDocument(filePath);
                doc.ConvertToImages(ImageType.BMP, outputDirectory, docName);
            }
        }
        #endregion




C# combine multiple pdf files, and convert to image


        #region combine pdf files and convert to Bmp
        internal static void combineAndConvertToBmp()
        {
            String[] files = new String[] { @"C:\demo1.pdf", @"C:\demo2.pdf", @"C:\demo3.pdf" };
            Stream stream = new MemoryStream();
            PDFDocument.CombineDocument(files, stream);
            PDFDocument doc = new PDFDocument(stream);
            String outputDirectory = @"C:\output\";
            doc.ConvertToImages(ImageType.BMP, outputDirectory, "fileName");
        }
        #endregion