XDoc.PDF
Features
Tech Specs
How-to C#
How-to VB.NET
Pricing
C# PDF: How to HTML5 Viewer & Editor PDF Create PDF Export File and Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF Viewer & Editor Work with Other SDKs Barcode Read Barcode Create OCR Twain
Convert PDF to Png, Gif, Bitmap ... Images
  |  
Home ›› XDoc.PDF ›› C# PDF: Convert PDF to Png, Gif, Bitmap ... Images

C#.NET PDF SDK - Convert & Render PDF to Images in C#.NET


Online C# Demo Codes for Converting PDF to Raster Images, .NET Graphics, and REImage in C#.NET Project




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


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.







C# convert single pdf file to image with image settings


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.




        #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




C# convert single pdf file to png with image options





        #region convert single pdf file to png with image options
        internal static void pdf2PngImage()
        {
            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.PNG, ops, outputDirectory, "fileName");
        }
        #endregion




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




.NET Class Namespace Required



In order to run the sample code, the following steps would be necessary.


Add necessary references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.PDF;





public override void ConvertToImages(ImageType targetType, String directory, String fileName)

Description:
     Convert all the PDF pages to target format images and output into the directory.

Parameters:




public override void ConvertToImages(ImageType targetType, Stream[] streams)

Description:
     Convert all the PDF pages to target format images and save them into streams.

Parameters:




public override void ConvertToImages(ImageType targetType, float zoomValue, String directory, String fileName)

Description:
     Convert all the PDF pages to target format images and output into the directory.

Parameters:




public override void ConvertToImages(ImageType targetType, float zoomValue, Stream[] streams)

Description:
     Convert all the PDF pages to target format images and save them into streams.

Parameters:




public override void ConvertToImages(ImageType targetType, int resolution, String directory, String fileName)

Description:
     Convert all the PDF pages to target format images and output into the directory.

Parameters:




public override void ConvertToImages(ImageType targetType, int resolution, Stream[] streams)

Description:
     Convert all the PDF pages to target format images and save them into streams.

Parameters:




public override void ConvertToImages(ImageType targetType, ImageOutputOption option, String directory, String fileName)

Description:
     Convert all the PDF pages to target format images and output into the directory.

Parameters:




public override void ConvertToImages(ImageType targetType, ImageOutputOption option, Stream[] streams)

Description:
     Convert all the PDF pages to target format images and save them into streams.

Parameters: