Windows平台下的方法

PDF to PNG Converter http://www.digitzone.com/pdftopng.html这个工具可以将PDF转化为多种格式,可以指定输出质量。该工具可以用命令行方式执行,因此可以用其他语言很方便的调用。

pdftopng

VeryPDFhttp://www.verypdf.com/pdf2tif/pdf-to-image/help.htm , 和前者功能大同小异,也支持命令行调用。

help_h2

Linux下的方法

最强大的应属ImageMagick(http://www.imagemagick.org/script/index.php)了,介绍很多,不再赘述。

纯JAVA的解决办法

利用Sun的开源项目,PDF Renderer(https://pdf-renderer.dev.java.net/)。

实例一:将PDF转换为Image对象

File file = new File("codigg.pdf");
RandomAccessFile 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
PDFPage page = pdffile.getPage(0);
 
//get the width and height for the doc at the default zoom
Rectangle rect = new Rectangle(0,0,
     (int)page.getBBox().getWidth(),
     (int)page.getBBox().getHeight());
 
//generate the image
Image img = page.getImage(
      rect.width, rect.height, //width & height
      rect, // clip rect
      null, // null for the ImageObserver
      true, // fill background with white
      true  // block until drawing is done
      );

实例二:将PDF转换为Graphics2D对象(page对象和实例一相同)

// create and configure a graphics object
BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = img.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 
// do the actual drawing
PDFRenderer renderer = new PDFRenderer(page, g2,
    new Rectangle(0, 0, 500, 500), null, Color.RED);
page.waitForFinish();
renderer.run();