PdftoImage-Convert PDF to Image by using PdfRenderer library

Bases on PDF Renderer library, we can easily develop many useful tools. Here is a example I wrote today, the aim is converting every pages of a pdf to images (png, if you need other format, you can use JAI).

import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

import javax.imageio.ImageIO;

import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;

public class Pdf2Image {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		if(args.length!=2)
		{
			System.err.println("Usage:Pdf2Image pdf imageFolder");
			return;
		}
		File file = new File(args[0]);
		RandomAccessFile raf;
		try {
			raf = new RandomAccessFile(file, "r");

			FileChannel channel = raf.getChannel();
			ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
			PDFFile pdffile = new PDFFile(buf);
			// draw the first page to an image
			int num=pdffile.getNumPages();
			for(int i=0;i

Source Code of PDF2Image

Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • BlinkList
  • blogmarks
  • blogtercimlap
  • connotea
  • DotNetKicks
  • Fark
  • Fleck
  • Gwar
  • Haohao
  • IndianPad
  • Internetmedia
  • LinkaGoGo
  • MyShare
  • Netscape
  • NewsVine
  • Rec6
  • Reddit
  • Scoopeo
  • Slashdot
  • StumbleUpon
  • Technorati
  • Webride

3 Responses to “PdftoImage-Convert PDF to Image by using PdfRenderer library

Leave a Reply

You must be logged in to post a comment.