how do I convert a pdf to a bitmap image in .net?

前端 未结 4 2021
悲哀的现实
悲哀的现实 2020-12-18 13:57

Looking for solution to convert a specified page of a pdf file to a bitmap image.

4条回答
  •  失恋的感觉
    2020-12-18 14:40

    (Disclaimer I worked on this component at Software Siglo XXI)

    If you don't want to mess with Ghostscript API and need a quick working solution to convert PDF documents to raster images (PNG, JPG, ...), you could use Super Pdf2Image Converter .NET. It's available for both 32 and 64 bit and is very cheap and effective.

    You can take a look here: http://softwaresigloxxi.com/SuperPdf2ImageConverter.html

    For instance, here's a sample code for converting:

    // Instantiate the component
    Pdf2ImageConverter p2i = new Pdf2ImageConverter(pdfPath);
    
    // Get page count of a PDF file
    int pages = p2i.GetPageCount();
    
    // Get size of any page
    int width, height;
    p2i.GetPageSize(1, out width, out height);
    
    // Convert any page of PDF to image file (preserving aspect ratio)
    p2i.GetImage(outputImagePath, pageNumber, resolution, imageFormat);
    
    // Or... convert any page of PDF to image (returns bitmap object)
    Bitmap bm = p2i.GetImage(pageNumber, resolution, width, height, imageFormat);
    

提交回复
热议问题