Convert PDF to Image without using Ghostscript DLL

前端 未结 4 1953
执念已碎
执念已碎 2020-11-29 03:56

Is there any way, I can convert HTML Document (file not URL) to Image, or PDF to image?

I am able to do the above using Ghostscript DLL , Is there any other way , I

4条回答
  •  清酒与你
    2020-11-29 04:37

    You can use below any one library for PDF to Image conversion

    Use Aspose.pdf link below: http://www.aspose.com/docs/display/pdfnet/Convert+all+PDF+pages+to+JPEG+Images

    code sample:

    Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(MyPdfPath));
    using (FileStream imageStream = new FileStream(MyOutputImage.png, FileMode.Create))
    {
         Resolution resolution = new Resolution(300);
        PngDevice pngDevice = new PngDevice(resolution);
        pngDevice.Process(pdfDocument.Pages[PageNo], MyOutputImage);
        imageStream.Close();
    }
    

    Use Bytescout PDF Renderer link below: http://bytescout.com/products/developer/pdfrenderersdk/convert-pdf-to-png-basic-examples

    code sample :

    MemoryStream ImageStream = new MemoryStream();
    RasterRenderer renderer = new RasterRenderer();
    renderer.RegistrationName = "demo";
    renderer.RegistrationKey = "demo";
    // Load PDF document.
    renderer.LoadDocumentFromFile(FilePath);
    for (int i = 0; i < renderer.GetPageCount(); i++)
    {
        // Render first page of the document to PNG image file.
        renderer.RenderPageToStream(i, RasterOutputFormat.PNG, ImageStream);
    }
    Image im = Image.FromStream(ImageStream);
    im.Save("MyOutputImage.png");
    ImageStream.Close();
    

提交回复
热议问题