XDoc.PDF
Features
Tech Specs
How-to C#
Pricing
How to Start Convert PDF Read PDF Build PDF 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 png, gif images using C#.net. Free open source examples


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 pdf file to png images with options


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. PngInterlance: True, create an Interlaced PNG; False, create a Non-interlaced PNG.
    Non-interlaced PNG encodes an image from start to finish; but Interlaced PNG encodes a whole image at low quality at beginning and then on each successive pass it encodes more of the detail, until the complete image has been processed.

  3. PngFilter: In PNG, a filter algorithm could be applied before compression which makes the image data for optimum compression.
    None: the scanline is transmitted unmodified.

    Sub: it transmits the difference between each byte and the value of the corresponding byte of the prior pixel.
    Up: it is just like the Sub filter except that the pixel immediately above the current pixel, rather than just to its left, is used as the predictor.
    Average: it uses the average of the two neighboring pixels (left and above) to predict the value of a pixel.
    Paeth: it computes a simple linear function of the 3 neighboring pixels (left, above, upper left), then chooses as predictor the neighboring pixel closest to the computed value.

  4. Zoom: Set zoom value to 2F. Use more pixels to render the page.

  5. Resolution: Set image resolution value in the JPEG file.



String inputFilePath = @"C:\1.pdf";
String outputFilePath = @"C:\output.png";

ImageOutputOption options = new ImageOutputOption();
//  Set output image type.
options.Type = ImageType.PNG;
//  Output image is grayscale.
options.Color = ColorType.Gray;
//  Set interlaced flag to true.
options.PngInterlance = true;
//  Set filter type to SUB
options.PngFilter = FilterPNG.SUB;
//  Set zoom value to 2F. Use more pixels to render the page.
options.Zoom = 2F;
//  Set resolution value in the PNG file to 300 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 PNG image
page.ConvertToImage(options, outputFilePath);


String inputFilePath = @"C:\1.pdf";
String outputFilePath = @"C:\output.png";

ImageOutputOption options = new ImageOutputOption();
//  Set output image type.
options.Type = ImageType.PNG;
//  Output image is color.
options.Color = ColorType.Color;
//  Set interlaced flag to false.
options.PngInterlance = false;
//  Set filter type to Average
options.PngFilter = FilterPNG.Average;
//  Set resolution value in the PNG file to 192 dpi.
options.Resolution = 192;

//  Open file and get the target page
PDFDocument doc = new PDFDocument(inputFilePath);
PDFPage page = (PDFPage)doc.GetPage(0);
//  Convert page to a PNG image
page.ConvertToImage(options, outputFilePath);






C# convert single pdf file to image with image settings


        #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 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