0

Sir, I am going to implement the module for converting the pdf to jpeg. At first , I can successfully create the pdf with one page. Then , I use the reference given by How to create image from PDF using PDFBox in JAVA to construct this model.

When it comes to building up the projects and compling, java heap space occcurs.

The below is my code

  protected void convertToImage(File file) {
    // TODO Auto-generated method stub
    if(!file.exists())
        return;

    try {
        PDDocument document = null; 
        try 
        {
            document = PDDocument.load(file);
        }
        catch (IOException ex)
        {
            System.out.println("" + ex);
        }

        List<PDPage>pages =  document.getDocumentCatalog().getAllPages();
        Iterator iter =  pages.iterator(); 

        int i =1;
        String name = null;

        while (iter.hasNext()) 
        {
            PDPage page = (PDPage) iter.next();
            PDResources resources = page.getResources();
            Map pageImages = resources.getImages();
            if (pageImages != null) 
            { 
                Iterator imageIter = pageImages.keySet().iterator();
                while (imageIter.hasNext()) {
                    String key = (String) imageIter.next();
                    PDXObjectImage image = (PDXObjectImage) pageImages.get(key);
                    image.write2file("H:\\image" + i);
                    i ++;
                }
            }
        }


    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 

}

Below is my eclipse ini section

  --launcher.XXMaxPermSize
  256M
  -showsplash
  org.eclipse.platform
  --launcher.XXMaxPermSize
  256m
  --launcher.defaultAction
  openFile
  -vmargs
  -Dfile.encoding=UTF-8
  -Dosgi.requiredJavaVersion=1.5
  -Dhelp.lucene.tokenizer=standard
  -Xms80m  <------cannot be further increased
  -Xmx512m  <------cannot be further increased
Community
  • 1
  • 1
Jeff Bootsholz
  • 2,971
  • 15
  • 70
  • 141

1 Answers1

0

One way to increase the heap size available to Eclipse is to edit the .ini file. You should find eclipse.ini in the same directory as your Eclipse executable. Specifically, increase the value for -Xmx, which represents maximum heap size:

-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
-vmargs
-Xms40m
-Xmx256m <-- increase this, e.g. 512m
ashatte
  • 5,442
  • 8
  • 39
  • 50