Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

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

Open
jxiaoyu opened this issue Jun 3, 2016 · 1 comment

Comments

@jxiaoyu
Copy link

jxiaoyu commented Jun 3, 2016

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
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants