Wednesday, June 27, 2012

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/

3 comments:

  1. You can convert PDF to any image format and vice versa with Aspose.PDF for Java library also. It offers many sample codes that developers can use to embed in their application.

    ReplyDelete
    Replies
    1. Java Development: Useful Api Converting Pdf To Image >>>>> Download Now

      >>>>> Download Full

      Java Development: Useful Api Converting Pdf To Image >>>>> Download LINK

      >>>>> Download Now

      Java Development: Useful Api Converting Pdf To Image >>>>> Download Full

      >>>>> Download LINK f9

      Delete