Wednesday, June 27, 2012

[Resolved] WARNING: getRGBImage returned NULL PDFToImage: Rendered Blank Image

Problem:
System returns the following message when converting a PDF file to Image using PDFBox,


Jun 27, 2012 3:45:07 PM org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap getRGBImage
SEVERE: Something went wrong ... the pixelmap doesn't contain any data.
Writing: output1.jpg
Jun 27, 2012 3:45:07 PM org.apache.pdfbox.util.operator.pagedrawer.Invoke process
WARNING: getRGBImage returned NULL
result: true



A blanked image will be generated in this case.

Resolution
1. You may try to add Java Advanced Image library I/O Tools to your project for the fix.
http://www.oracle.com/technetwork/java/current-142188.html


2. Include the JAR jai_imageio.jar to your project and execute the project again.


3. Though there is still an WARNING message of EOC marker not found. Codestream is corrupted. shown in the output console, the image is generated successfully.

The usage of PDFBox can be found in the following URL:
http://yp-javadev.blogspot.hk/2012/06/useful-api-converting-pdf-to-image.html

Useful API converting PDF to image

1. Download the tool PDFBox (e.g. pdfbox-app-1.7.0.jar) via the following URL:


2. Include the library in your java program. The following source code is attached for your reference.



package com.test;

import java.awt.Toolkit;
import java.awt.image.BufferedImage;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFImageWriter;

public class PDFBoxPreviewTest {

       /**
        * @param args
        */
       public static void main(String[] args) {
              try {
                     String path = "D:\\temp\\a.pdf";
                     PDFBoxPreviewTest t = new PDFBoxPreviewTest();
                     t.getDocument(path);
              } catch (Exception e) {

                     System.out.println(e.getMessage());
              }
       }

       private PDDocument getDocument(String path) throws Exception {
              PDDocument document = null;

              document = PDDocument.load(path);

              PDFImageWriter writer = new PDFImageWriter();
              boolean success = writer.writeImage(document, "jpg", "", 1, 1,
                           "myFileName", BufferedImage.TYPE_INT_RGB, Toolkit
                                         .getDefaultToolkit().getScreenResolution());
              System.out.println(success);

              return document;
       }
}

3. myFileName.jpg will be generated!


Source Code can be found here:
http://test-pdfbox.googlecode.com/svn/trunk/

Monday, June 18, 2012

[RESOLVED] A Java Runtime Environment (JRE) or Java Development Toolkit (JDK) must be available in order to run Eclipse

A Java Runtime Environment (JRE) or Java Development Toolkit (JDK) must be available in order to run Eclipse.


Solution:

Java must be installed in your Windows in order to run eclipse.
http://java.com/en/download/index.jsp

After installed Java, set the JAVA PATH in System Variable.