package com.wsy;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.print.Book;
import java.awt.print.PageFormat;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.JTree;
import javax.swing.JWindow;
import javax.swing.Timer;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.filechooser.FileFilter;
import com.sun.pdfview.FullScreenWindow;
import com.sun.pdfview.OutlineNode;
import com.sun.pdfview.PDFDestination;
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFObject;
import com.sun.pdfview.PDFPage;
import com.sun.pdfview.PDFPrintPage;
import com.sun.pdfview.PageChangeListener;
import com.sun.pdfview.PagePanel;
import com.sun.pdfview.ThumbPanel;
import com.sun.pdfview.action.GoToAction;
import com.sun.pdfview.action.PDFAction;
import com.util.CreatecdIcon;
public class MainFrame extends JFrame implements PageChangeListener, TreeSelectionListener,KeyListener{
/**
* @param args
*/
//放置主内容的面板
JPanel jpmain = new JPanel();
//放置读取PDF文档内容的面板
PagePanel jp;
//全屏显示面板
FullScreenWindow fullScreen;
//缩位图面板
ThumbPanel thumbs;
JScrollPane documentScroller = new JScrollPane();
//PDFRender包中获取PDF文档的PDFFile类
PDFFile pdffile;
//用户填写页码的文本框
JTextField pageField;
int curpage = -1;
JTabbedPane tabbedPane;
//用于获取大纲的OutlineNode对象
OutlineNode outline = null;
JButton smallButton;
JButton fullScreenButton;
PageFormat pformat = PrinterJob.getPrinterJob().defaultPage();
String docName;
private Timer activityMonitor;
private SimulateActivity activity;
PagePanel fspp;
PageBuilder pb = new PageBuilder();
private Point loc = null;
private Point tmp = null;
private boolean isDragged = false;
public MainFrame() {
// TODO 自动生成构造函数存根
try {
// com.sun.java.swing.plaf.windows.WindowsLookAndFeel
// javax.swing.plaf.metal.MetalLookAndFeel
// com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel
String lookAndFeel ="com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
UIManager.setLookAndFeel(lookAndFeel);
} catch (UnsupportedLookAndFeelException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setTitle("电子阅读器");
setSize(new Dimension(900, 700));
getContentPane().setLayout(null);
getContentPane().add(CreateMenuBar());
/*
* 创建左边的缩位图面板
*/
thumbs = new ThumbPanel(null);
thumbscroll = new JScrollPane(thumbs,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
thumbscroll.getViewport().setView(thumbs);
thumbscroll.getViewport().setBackground(Color.gray);
tabbedPane=new JTabbedPane();
tabbedPane.addTab(null, CreatecdIcon.add("02.gif"), thumbscroll);
tabbedPane.addTab(null, CreatecdIcon.add("05.gif"), null);
tabbedPane.setTabPlacement(JTabbedPane.LEFT);
getContentPane().add(tabbedPane);
tabbedPane.setBounds(0, 63, 270, 600);
//getContentPane().add(thumbscroll);
/*
*创建中间的内容面板
*/
contentPanel = new JScrollPane();
jp=new PagePanel();
jp.addMouseListener(new JPMouseAction());
jp.addMouseMotionListener(new JPMouseMotionAction());
jpmain.setLayout(new GridLayout(0, 1));
contentPanel.setViewportView(jpmain);
contentPanel.setBounds(270, 63, 600, 600);
getContentPane().add(contentPanel);
/*
* 创建工具栏
*/
getContentPane().add(CreateToolBar());
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screen.width - getWidth()) / 2;
int y = (screen.height - getHeight()) / 2;
setLocation(x, y);
}
public static void main(String[] args) {
// TODO 自动生成方法存根
new MainFrame().setVisible(true);
}
public JMenuBar CreateMenuBar() {
final JMenuBar menuBar = new JMenuBar();
menuBar.setBounds(0, 0, 1000, 25);
final JMenu newItemMenuItem1 = new JMenu();
newItemMenuItem1.setText("文件(F)");
menuBar.add(newItemMenuItem1);
final JMenuItem newItemMenuItem_1 = new JMenuItem();
newItemMenuItem_1.setText("打开");
newItemMenuItem1.add(newItemMenuItem_1);
newItemMenuItem_1.setToolTipText("Open PDF file");
newItemMenuItem_1
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent evt) {
// TODO 自动生成方法存根
doOpen();
}
});
final JMenuItem newItemMenuItem = new JMenuItem();
newItemMenuItem.setText("页面设置");
newItemMenuItem1.add(newItemMenuItem);
newItemMenuItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成方法存根
doPageSetup();
}
});
final JMenuItem newItemMenuItem_3 = new JMenuItem();
newItemMenuItem_3.setText("打印");
newItemMenuItem_3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成方法存根
doPrint();
}
});
newItemMenuItem1.add(newItemMenuItem_3);
final JMenuItem newItemMenuItem_2 = new JMenuItem();
newItemMenuItem_2.setText("退出");
newItemMenuItem_2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成方法存根
doClose();
System.exit(0);
}
});
newItemMenuItem1.add(newItemMenuItem_2);
return menuBar;
}
Action nextAction = new AbstractAction() {
public void actionPerformed(ActionEvent evt) {
doNext();
}
};
Action prevAction = new AbstractAction() {
public void actionPerformed(ActionEvent evt) {
doPrev();
}
};
Action BigAction=new AbstractAction(){
public void actionPerformed(ActionEvent arg0) {
PDFPage page = pdffile.getPage(curpage);
Rectangle rect = new Rectangle(0,0,
(int)page.getBBox().getWidth(),
(int)page.getBBox().getHeight());
//generate the image
Image img = page.getImage(
rect.width*2, rect.height*2, //width & height
rect, // clip rect
null, // null for the ImageObserver
true, // fill background with white
true // block until drawing is done
);
if(jpmain!=null){
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
PDF.zip (54个子文件)
PDF
res
02.PNG 3KB
last.gif 1KB
05.PNG 3KB
back.gif 1KB
page.gif 2KB
big.gif 616B
rewrite.gif 1KB
02.GIF 910B
preview.png 3KB
next.gif 1KB
small.gif 582B
frist.gif 1KB
last.png 3KB
05.GIF 978B
fullScreen.gif 2KB
Thumbs.db 8KB
src
com
wsy
MainFrame.java 25KB
PDFRead.java 6KB
util
CreatecdIcon.java 358B
bin
com
wsy
MainFrame$1.class 633B
MainFrame.class 18KB
MainFrame$12.class 766B
MainFrame$13.class 1KB
MainFrame$3.class 2KB
MainFrame$8.class 886B
MainFrame$10.class 716B
MainFrame$11.class 712B
MainFrame$PrintThread.class 1KB
MainFrame$9.class 708B
MainFrame$5.class 635B
PDFRead.class 6KB
MainFrame$JPMouseAction.class 1KB
MainFrame$14.class 1KB
MainFrame$6.class 634B
MainFrame$2.class 633B
MainFrame$PerformFullScreenMode.class 1KB
MainFrame$4.class 2KB
MainFrame$SimulateActivity.class 1KB
MainFrame$PageBuilder.class 1KB
MainFrame$7.class 768B
MainFrame$JPMouseMotionAction.class 1KB
util
CreatecdIcon.class 709B
.classpath 1KB
.settings
org.eclipse.jdt.core.prefs 598B
.project 379B
lib
pdfbox-tools-2.0.15.jar 76KB
fontbox-2.0.15.jar 1.49MB
junit-4.7.jar 227KB
commons-logging-1.2.jar 60KB
pdfbox-2.0.15.jar 2.45MB
pdfbox-debugger-2.0.15.jar 239KB
PDFRenderer.jar 1.99MB
xmpbox-2.0.15.jar 129KB
preflight-2.0.15.jar 241KB
共 54 条
- 1
资源评论
- xyunhua2019-07-05很不错的代码!简单直接可用,插到我的项目里面了,赞一个!
- 周石生2021-11-23这个能将读取到的pdf含表格边框生成word文档吗
快乐的,开心的。。
- 粉丝: 2
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功