-
大小: 1.42MB文件类型: .rar金币: 1下载: 0 次发布日期: 2023-10-31
- 语言: Java
- 标签: PDFRenderer
资源简介
如果生成PDF文件,大家估计会选择iText jar包,但是如果想用在一个Panel上看PDF,就要选择PDFRenderer.jar (貌似pdfbox也可以),现在将PDFRenderer jar包以及例子放到了一起,供大家参考
代码片段和文件信息
package panelView;
//import com.sun.pdfview.PDFFile;
//import com.sun.pdfview.PDFPage;
//import com.sun.pdfview.PagePanel;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import javax.swing.*;
import org.pdfbox.pdfviewer.PDFPagePanel;
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;
import com.sun.pdfview.PagePanel;
/**
* An example of using the PagePanel class to show PDFs. For more advanced
* usage including navigation and zooming look ad the
* com.sun.pdfview.PDFViewer class.
*
* @author joshua.marinacci@sun.com
*/
public class Main {
public static void setup() throws IOException {
//set up the frame and panel
Jframe frame = new Jframe(“PDF Test“);
frame.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
PagePanel panel = new PagePanel();
frame.add(panel);
frame.pack();
frame.setVisible(true);
//load a pdf from a byte buffer
File file = new File(“C:\\Documents and Settings\\Administrator\\デスクトップ\\ー ~ 教育記録-20090513.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);
// show the first page
PDFPage page = pdffile.getPage(0);
panel.showPage(page);
}
public static void main(final String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
Main.setup();
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2087109 2010-02-10 14:17 PDFRenderer.jar
文件 1881 2010-02-10 14:19 Main.java
----------- --------- ---------- ----- ----
2088990 2
- 上一篇:JAVA数学库colt-1.2.0
- 下一篇:Java Web宿舍管理系统
评论
共有 条评论