`

(word 转换为pdf) pdf 转换为图片

    博客分类:
  • java
阅读更多

package coms;


import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import javax.swing.SwingUtilities;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;

public class PdfToJpgTest {
 public static void setup() throws IOException {

  // load a pdf from a byte buffer
  File file = new File(
    "c://A.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);

  System.out.println("页数: " + pdffile.getNumPages());

  for (int i = 1; i <= pdffile.getNumPages(); i++) {
   // draw the first page to an image
   PDFPage page = pdffile.getPage(i);

   // 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
     );

   BufferedImage tag = new BufferedImage(rect.width, rect.height,
     BufferedImage.TYPE_INT_RGB);
   tag.getGraphics().drawImage(img, 0, 0, rect.width, rect.height,
     null);
   FileOutputStream out = new FileOutputStream(
     "c://picture//"
       + i + ".jpg"); // 输出到文件流
   JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
   encoder.encode(tag); // JPEG编码

   out.close();
  }

  // show the image in a frame
  // JFrame frame = new JFrame("PDF Test");
  // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  // frame.add(new JLabel(new ImageIcon(img)));
  // frame.pack();
  // frame.setVisible(true);
 }

 public static void main(final String[] args) {
  SwingUtilities.invokeLater(new Runnable() {
   public void run() {
    try {
     PdfToJpgTest.setup();
    } catch (IOException ex) {
     ex.printStackTrace();
    }
   }
  });
 }

}

 

必须需要一个jar 包http://download.csdn.net/detail/klo0704/4041564

分享到:
评论

相关推荐

    Word转换成PDF转换器 v3.0.exe

    Word转换成PDF转换器为Word文档转换成Adobe PDF最完整的解决方案。 Word转换成PDF转换器能批量转换微软办公软件格式到PDF, 节省时间, 同时支持多核CPU,让你转换的过程中更快捷更有效。 Word转换成PDF转换器可以...

    Word文档转换为图片Pdf,Word文档扫描成Pdf

    Word转换为图片Pdf 1、 Word转换为Pdf,程序很多,但转换后的Pdf,还可以复制,虽可以加密禁止复制,但市场上太多的Pdf,还可以把Pdf转换Word等其他格式,很容易被别人利用和剽窃,如何彻底的自己的Word文档,可以被...

    WORD转换成PDF的软件

    word转pdf(pdftoword)工具是一款功能强大好用的word转pdf软件工具,在1.3版本中新增加了pdf转word的功能,可以实现pdf与word的相互转换,界面简单,功能稳定,支持批量转换,操作起来非常方便,支持多种流行文档...

    word 转换为pdf进行预览

    word 转换为pdf进行预览,在线预览word文档,word文档通过wps接口转换为pdf,C# word文档通过wps接口转换为pdf;引用的第三方dll 属性必须设置为可复制!!!

    VB程序Word转换成PDF

    VBA程序将Word转成PDF,可以做出WSF供Java和C程序调用。此程序调通过,实际项目上用到过,仅供参考。

    C#将WORD转换为PDF的Demo

    VS2010写的将Word转换成PDF的例子,例子页面为About.aspx,服务器需要安装Office2010

    C# word 转换成 pdf Demo

    C# word 转换成 pdf DemoC# word 转换成 pdf DemoC# word 转换成 pdf DemoC# word 转换成 pdf DemoC# word 转换成 pdf DemoC# word 转换成 pdf Demo

    word转换pdf、excel转换pdf、jpeg转换pdf等的工具PDF转换器注册码

    word转换pdf、excel转换pdf、jpeg转换pdf等的工具PDF转换器注册码

    将WORD转换成PDF

    此软件能将WORD转换成PDF的软件,非常实用

    pdf转word工具(pdf转换成word转换器) v2.0中文破解版.rar

    pdf转word工具(pdf转换成word转换器) v2.0中文破解版.rar简单实用

    用C#.NET实现生成PDF文档和将WORD转换为PDF

    用C#.NET实现生成PDF文档和将WORD转换为PDF

    免费pdf转换成word转换器pdf转换成word转换器

    免费 pdf转换成word 转换器

    PDF转换成word转换器

    PDF转换成word转换器,转换出来的是图片格式的,亲测可用

    pdfword转换器支持批量转换

    pdfword转换器支持批量转换pdfword转换器支持批量转换pdfword转换器支持批量转换pdfword转换器支持批量转换pdfword转换器支持批量转换pdfword转换器支持批量转换pdfword转换器支持批量转换pdfword转换器支持批量转换...

    aspose将word转换为pdf等格式

    将word转换为pdf等格式,该jar为已破解的jar,仅限于学习,非商业用途,存在问题可联系博主,博主会细心帮助解决!

    迅捷word转换成pdf转换器在线

    迅捷在线PDF转Word软件能够瞬间将需要转换的PDF格式转换成Word格式,目前PDF转换成Word转换器在线支持多文件格式转换包括在线PDF转Word、在线Word转PDF、在线Excel转PDF、在线PPT转PDF四种常见办公格式

    批量WORD转PDF转换器

    批量Word转PDF转换器是一款Windows平台下的Word转PDF转换工具,它可以方便快捷地一次性将多个Word文件转换成PDF格式文件。由于软件抛弃了传统虚拟打印生成PDF的方法,而采用直接分析WORD文件并转换到PDF的技术,因此...

    word转pdf(Aspose.Word)

    使用aspose.word将word文档转换成pdf格式,核心代码: Document doc = new Document(wordFolderPath); doc.Save(pdfFolderPath, SaveFormat.Pdf); 本程序实现了将制定word文件转换成pdf格式,或者制定文件夹,将...

    Word转换为图片Pdf 1.5.0.18 破解版内存注册机

    1、Word转换为Pdf,程序很多,但转换后的Pdf,还可以复制,虽可以加密禁止复制,但市场上太多的Pdf,还可以把Pdf转换Word等其他格式,很容易被别人利用和剽窃,如何彻底的自己的Word文档,可以被人浏览,查看,而不被...

    将Word文档转换为PDF文件

    使用C# 2008开发,将Word文档转换为PDF,还可以将多个PDF文档合并为一个PDF,实现书签写入。

Global site tag (gtag.js) - Google Analytics