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

java.lang.OutOfMemoryError: Java heap space from SimpleRenderer #65

@daynok

Description

@daynok

Trying to evaluate ghost4j but am getting an outofmemory error on ghost4j 1.0.1
My env:
64 bit linux (arch)
Java 1.8.0_131

Tried multiple times to attach pdf to this ticket.. github kept giving me errors so created a repo with support files

  • Driver.java (test app)
  • Pro-Git.pdf (test pdf, 7.7M)

https://github.com/daynok/ghost4j-outofmemory

Ran pdfinfo on the pdf and as far as I can tell it looks good. Also opened the pdf in firefox without issue.

From what I can tell the outofmemory error gets thrown at
renderer.render(document);

I'm not sure if I'm doing something wrong programmatically or what.

End goal, convert pdf pages to png's.

package com.medata;

import java.io.File;
import org.ghost4j.document.PDFDocument;
import org.ghost4j.renderer.SimpleRenderer;

public class Driver {

    public static void main(String args[]) {
            try {
                    String sourcePath = args[0];
                    System.out.println("Reading files from path:" + sourcePath);

                    File[] fileList = new File(sourcePath).listFiles();

                    for(File pdfFile : fileList) {
                            System.out.println("starting to process file: " + pdfFile.getName());
                            long startIterTime = System.currentTimeMillis();
                            PDFDocument document = null;
                            SimpleRenderer renderer = null;

                            try {

                                    document = new PDFDocument();
                                    document.load(pdfFile);
                                    renderer = new SimpleRenderer();
                                    renderer.setResolution(300);
                                    renderer.render(document);
                            }
                            catch(Exception e) {
                                    throw e;
                            }
                            finally {
                                    renderer = null;
                                    document = null;
                            }
                            long totalIterTime = System.currentTimeMillis() - startIterTime;
                            System.out.println("file:" + pdfFile.getName() + " total time:" + totalIterTime + " ms, total time sec:" + (totalIterTime/1000));
                    }
            }
            catch(Exception e) {
                    e.printStackTrace();
            }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions