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 Jpg Converter Library
How to convert PDF to JPG image files using C#.net in web, windows application. Free open source examples.


C#.NET PDF to Jpg Converting & Conversion Control for .NET Framework. Online Free Trial Download.





In this tutorial, you learn how to convert PDF to jpg using C# in ASP.NET web app, and Windows application.

How to PDF file to JPG images using C#

  1. Download XDoc.PDF JPEG Converter C# library
  2. Install C# library to convert PDF document to JPG images
  3. Step by Step Tutorial




























RasterEdge PDF to JPEG converting control SDK (XDoc.PDF for .NET) supports converting PDF document to JPEG image file in .NET developing platforms using simple C# programming code. JPEG image file, owing to its small-size feature, is counted as a more suitable choice for publishing in web services than PDF document file.

Using this C#.NET PDF to JPEG conversion library component toolkit, C# developers can easily and quickly convert a large-size multi-page PDF document to a group of high-quality separate JPEG image files within .NET projects, including ASP.NET web and Window Forms applications.

When using RasterEdge PDF to JPEG converter library control SDK, C# developers may customize the names of all converted JPEG image files in .NET class application. In the following example, this C#.NET PDF to JPEG converter library will name the converted JPEG image file Output.jpg.





PDF to Jpeg with image options


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


  1. Color: Output image is Monochrome, Gray, Color.

  2. JpegProgressive: If true, create Progressive JPEG image; If false, create Baseline JPEG.
    Baseline JPEG
    To encode image line by line from top to bottom. When opening a large baseline JPEG image through a very slow internet connection, the image would be renderred from top to bottom.

    Progressive JPEG: To encode image initially with full-size but low-quality pixellated. When opening a large baseline JPEG image through a very slow internet connection, the image would be renderred in full size looking pixelated at beginning, and then the quality becomes more and more clear.

  3. JpegQualityLevel: Quality level, 0, 20, 40, 60, 80, 100 (Highest Quality).

  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.jpg";

ImageOutputOption options = new ImageOutputOption();
//  Set output image type.
options.Type = ImageType.JPEG;
//  Output image is grayscale.
options.Color = ColorType.Gray;
//  Progressive
options.JpegProgressive = true;
//  Quality level, 0, 20, 40, 60, 80, 100 (Highest Quality).
options.JpegQualityLevel = 80;
//  Set zoom value to 2F. Use more pixels to render the page.
options.Zoom = 2F;
//  Set resolution value in the JPEG 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 JPEG image
page.ConvertToImage(options, outputFilePath);


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

ImageOutputOption options = new ImageOutputOption();
//  Set output image type.
options.Type = ImageType.JPEG;
//  Output image is color.
options.Color = ColorType.Color;
//  Baseline
options.JpegProgressive = false;
//  Quality level, 0, 20, 40, 60, 80, 100 (Highest Quality).
options.JpegQualityLevel = 20;
//  Set resolution value in the JPEG 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 JPEG image
page.ConvertToImage(options, outputFilePath);






C#: Convert, change PDF to high quality JPEG pictures in C#.NET


Following demo code will show how to convert all PDF pages to Jpeg images with C# .NET.



        #region pdf to Jpeg (one page to file)
        internal static void convertPdfPageToJpeg()
        {
            String inputFilePath = @"";
            String outputDirectory = @"";
            PDFDocument doc = new PDFDocument(inputFilePath);
            int pageIdx = 0; //first page
            BasePage page = doc.GetPage(pageIdx);
            page.ConvertToImage(ImageType.JPEG, outputDirectory + "fileName.jpeg");
        }
        #endregion

        #region pdf to Jpeg (stream to stream)
        internal static void convertPdfPageToJpeg()
        {
            String inputFilePath = @"";
            String outputDirectory = @"";
            byte[] arr = File.ReadAllBytes(inputFilePath);
            Stream stream = new MemoryStream(arr);
            PDFDocument doc = new PDFDocument(stream);
            int pageIdx = 0; //first page
            BasePage page = doc.GetPage(pageIdx);
            Stream outputStream = new MemoryStream();
            page.ConvertToImageStream(ImageType.JPEG, outputStream);
        }
        #endregion

        #region pdf to Jpeg (all page)
        internal static void convertPdfToJpeg()
        {
            String inputFilePath = @"";
            String outputDirectory = @"";
            PDFDocument doc = new PDFDocument(inputFilePath);
            doc.ConvertToImages(ImageType.JPEG, outputDirectory, "fileName");
        }
        #endregion




C# create JPEG images from multiple pdf files (batch conversion)


        #region pdf to Jpeg (batch files and single tread)
        internal static void pdfFilesToJpeg()
        {
            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.JPEG, outputDirectory, docName);
            }
        }
        #endregion




C# convert, change pdf to jpeg with specified dpi resolution


        #region convert pdf file to Jpeg with specified resolution
        internal static void convertPdfFileToJpegWithSpecified()
        {
            String inputFilePath = @"";
            String outputDirectory = @"";
            PDFDocument doc = new PDFDocument(inputFilePath);
            doc.ConvertToImages(ImageType.JPEG, 300, outputDirectory, "fileName");//create images in 300dpi.
        }
        #endregion




C# make, turn pdf to jpeg (.jpeg, .jpg) with specified colorspace (color, grayscale, monochrome or black & white)


        #region convert pdf file to Jpeg with specified colorspace settings
        internal static void convertPdfFileToJpegWithSpecifiedSettings()
        {
            String inputFilePath = @"";
            String outputDirectory = @"";
            PDFDocument doc = new PDFDocument(inputFilePath);
            //set image output settings
            ImageOutputOption option = new ImageOutputOption();
            option.Color = ColorType.Monochrome;
            //...
            
            doc.ConvertToImages(ImageType.JPEG, option, outputDirectory, "fileName");//create images with specified settings.
        }
        #endregion