應用程式產生PDF文件,可採用iText(jini第27期opensource電子期與Run!PC某一期都有介紹),
而現在Adobe公司提供 Adobe View for JavaBean 讓 Java 開發人員可以操控PDF文件。
以下是流程、程式碼、參考資源與執行視窗
流程:
1.安裝 Java virtual Machine
Sun Microsytem
http://java.sun.com/j2se/1.5.0/download.jsp
2.下載 Acrobat View for JavaBean
Adobe Corporation
http://download.adobe.com/pub/adobe/magic/acrobatviewer/win/1.x/bean.zip
3.解壓縮
把下載下來的bean.zip解壓縮到c槽底下的AdobeViewer檔案夾,
AdobeViewer檔案夾自己建立。
4.設定環境變數
4.1 新增變數
名稱:AdobeViewer
路徑:C:\adobeViewer
4.2 增加路徑到 CLASSPATH
原有的路徑;%AdobeViewer%\acrobat.jar;%AdobeViewer%\MRJToolkitStubs.zip;.
(記得最後有一個點)
5.程式碼
5.1 Notepad
新增一個檔案在c槽底下,
名為PDFViwer.java
5.2 輸入程式
6.執行程式
6.1 編譯程式
javac PDFViewr.java
6.2 執行程式
java PDFViewer
7.關閉程式
Ctrl + c
程式碼:
import com.adobe.acrobat.*;
import java.awt.*;
import java.io.*;
public class PDFViewer
{
Frame frame;
Viewer viewer;
public PDFViewer() { }
public static void main(String [] args)
{
try{
PDFViewer pdf = new PDFViewer();
pdf.configure();
pdf.display();
}catch(Exception ex) { }
}
public void configure()
{
try{
frame=new Frame("PDFViewer Application");
viewer = new Viewer();
frame.setLayout(new BorderLayout());
frame.add(viewer, BorderLayout.CENTER);
InputStream input = new FileInputStream(new File("c:/JVM.pdf"));
viewer.setDocumentInputStream(input);
viewer.setEnableDebug(true);
viewer.setProperty("Default_Page_Layout", "SinglePage");
viewer.setProperty("Default_Zoom_Type", "FitPage");
viewer.setProperty("Default_Magnification", "100");
viewer.zoomTo(1.0);
}catch(Exception ex) {}
}
public void display()
{
try{
viewer.activate();
frame.setSize(400, 500);
frame.pack();
frame.show();
}catch(Exception ex) { }
}
}
參考資料:
a.java.net-Aticiles「Accessing a PDF Document with the Acrobat Viewer JavaBean」
URL:http://today.java.net/pub/a/today/2005/10/20/accessing-pdf-with-acrobat-viewer-javabean.html
b.bean.zip 的 API 文件與範例
c.sun Inc-JDK 5.0 API
URL:http://java.sun.com/j2se/1.5.0/docs/api/
執行視窗
ps.
a) 文章寫的不是很好,請多多包含 ^^"
b) 此文作為拋磚玉一下,有玩過的可以分享一下心得。
04 二月 · 星期六 2006
Adobe View for JavaBean
我試過了,很好用,但是中文顯示有問題,請問有解嗎?
由...發表 施光隆 on 五月 26, 2006 at 11:02 上午 CST #