zippy1978 / ghost4j

Java wrapper for Ghostscript C API + PS/PDF document handling API
http://www.ghost4j.org
GNU Lesser General Public License v3.0
64 stars 38 forks source link

I used SimpleRenderer to convert pdf to images, but sometimes caused jvm crashed #50

Open jxiaoyu opened 8 years ago

jxiaoyu commented 8 years ago

This is my method

public static void pdf2Image(String file) {
        String os = System.getProperty("os.name").toLowerCase();
        if (os.indexOf("windows") >= 0) {
            System.setProperty("jna.library.path", "C:\\Program Files\\gs\\gs9.18\\bin\\");
        }
        try {

            // load PDF document
            PDFDocument document = new PDFDocument();

            document.load(new File(file));

            // create renderer
            SimpleRenderer renderer = new SimpleRenderer();

            // set resolution (in DPI)
            renderer.setResolution(300);

            // render
            List<Image> images = renderer.render(document);

            // write images to files to disk as PNG
            try {
                for (int i = 0; i < images.size(); i++) {
                    log.info('page num: ' + i)
                    ImageIO.write((RenderedImage) images.get(i), "png", new File("./images/" + (i + 1) + ".png"));
                }
            } catch (IOException e) {
                System.out.println("ERROR: " + e.getMessage());
                log.error('error', e)
            }

        } catch (Exception e) {
            System.out.println("ERROR: " + e.getMessage());
            log.error('error', e)
            return
        }

    }

And the hs_err_pid.log is attached

hs_err_pid22358.txt

dekonunes commented 6 years ago

Don't working for me too,

My code crash in this line: List<Image> images = renderer.render(document);

My JAVA is 1.8.0_161