一个用Java写出的PDF阅读器的源代码

在运行之前需要在http://www.adobe.com/products/acrviewer/acrvdnld.html?name=accept下载Acrobat Viewer JavaBean API ,将acrobat.jar文件部署到classpath中

源代码如下:

package java学习.PDFProcess.AcrobatViewer.Example;

import java.awt.*;
import java.awt.event.*;
import java.io.*;

import com.adobe.acrobat.Viewer;

public class SampleReader extends Viewer {

    public SampleReader() throws Exception {
    }

    public static void main(String args[]) {
 Frame f = new Frame("Sample Acrobat Reader");

 f.setLayout(new BorderLayout());
 Label top = new Label("Acrobat Reader created using adobe.Acrobat.Viewer", Label.CENTER);
 top.setBackground(Color.red);
 f.add(top, BorderLayout.NORTH);
 f.add(new Label("Adobe Acrobat Reader - Alpha release - 1998", Label.CENTER), BorderLayout.SOUTH);
 try {

     // Construct a acrobat object aka Acrobar Reader
     // note that you must also call its activate
     // method before you show the containing panel,
     // in this case the frame object.

     // The acrobat object is declared as final
     // so that it could be referenced in the
     // following windowClosing method.

     final Viewer acrobat = new Viewer();

     f.addWindowListener(new WindowAdapter() {
  public void windowClosing(WindowEvent e) {

      if (acrobat != null) {

   // The deactivate method will ensure that the
   // acrobat.properties file is saved
   // upon exit.

   acrobat.deactivate();
      }

      System.exit(0);
  }
     });

     if (args.length > 0) {
  try {

      // assumes that args[0] is the name of a file

      FileInputStream in = new FileInputStream(args[0]);
      acrobat.setDocumentInputStream(in);

  } catch (FileNotFoundException x) {
      System.out.println("File not found!");
      // The viewer will display a blank screen.
      // You can then use the Viewer's pop-up menu
      // to open a local or remote PDF file.
  }
     }

     f.add(acrobat, BorderLayout.CENTER);

     // you must call activate to enable the Viewer object
     // to layout its sub-components and the further initialization
     // needed for it to be displayed.

     acrobat.activate(); //WithoutBars();

 } catch (Exception x) {
     f.add(new Label("Unable to create an Acrobat Reader"), "Center");
 }

 f.setSize(400, 400);
 f.show();


    }
}

 


转自

http://blog.donews.com/karim/archive/2006/02/19/732857.aspx

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值