如题,目的只是想做个DOC和PDF的只读浏览器

解决方案 »

  1.   

    DOC可能麻烦一点,很难完美显示的。
    PDF以前用过开源类库iText,你可以试一下。
    另外gogole到如下自资料:网址: http://bbs.chinajavaworld.com/thread.jspa?threadID=4488近来发现问这方面的问题特别多,花了点时间,找了一些资料,并整理出一个简单例子
    Java操作PDF http://www.lowagie.com/Java操作Word,Excel,Access
    参考:
    http://danadler.com/jacob/
    http://jakarta.apache.org/poi/
    http://www.onjava.com/pub/a/onjava/2003/01/22/poi.html
    http://www.csdn.net/develop/article/15/15311.shtm
    http://forum.java.sun.com/thread.jsp?forum=40&thread=382666&tstart=0&trange=15一个jacob操作Word的例子,操作Excel,Access,Outlook的例子jacob的sample目录中有
    import java.io.File;
    import com.jacob.com.*;
    import com.jacob.activeX.*;
    public class WordTest {  public static void main(String[] args) {
          WordBean word=new WordBean();
          word.openWord(true);
          word.createNewDocument();
          word.insertText("Hello word.");
      }
    }
    import com.jacob.activeX.*;
    import com.jacob.com.*;
    public class WordBean extends java.awt.Panel
    {
      private ActiveXComponent MsWordApp = null;
      private Dispatch document = null;
      public WordBean()
      {
          super();
      }
      public void openWord(boolean makeVisible)
      {
    //Open Word if we've not done it already
          if (MsWordApp == null)
          {
              MsWordApp = new ActiveXComponent("Word.Application");
          }
    //Set the visible property as required.
          Dispatch.put(MsWordApp, "Visible",
                       new Variant(makeVisible));
      }
      public void createNewDocument()
      {
    //Find the Documents collection object maintained by Word
          Dispatch documents =
                  Dispatch.get(MsWordApp,"Documents").toDispatch();
    //Call the Add method of the Documents collection to create
    //a new document to edit
          document = Dispatch.call(documents,"Add").toDispatch();
      }
      public void insertText(String textToInsert)
      {
    // Get the current selection within Word at the moment. If
    // a new document has just been created then this will be at
    // the top of the new doc
          Dispatch selection =
                  Dispatch.get(MsWordApp,"Selection").toDispatch();
    //Put the specified text at the insertion point
          Dispatch.put(selection,"Text",textToInsert);
      }
      public void saveFileAs(String filename)
      {
          Dispatch.call(document,"SaveAs",filename);
      }
      public void printFile()
      {
    //Just print the current document to the default printer
          Dispatch.call(document,"PrintOut");
      }
      public void closeDocument()
      {
    // Close the document without saving changes
    // 0 = wdDoNotSaveChanges
    // -1 = wdSaveChanges
    // -2 = wdPromptToSaveChanges
          Dispatch.call(document, "Close", new Variant(0));
          document = null;
      }
      public void closeWord()
      {
          Dispatch.call(MsWordApp,"Quit");
          MsWordApp = null;
          document = null;
      }
    }
      

  2.   

    terry6394(小猪,向前跑!) 
    能不能写一些注释,这样看不是很清楚啊。
      

  3.   

    二楼的方法只是能实现对pdf、doc等文件的读写操作,但要显示,目前还达不到。itext网站FAQ栏明确指出itext不能显示pdf,jacob也一样
      

  4.   

    用pdfbox可以显示PDF文件,到官方网站去下载最新版0.72大概20多M
      

  5.   

    diggywang() ( ) 信誉:100  2006-7-7 14:28:26  得分: 0  
     
     
       
    二楼的方法只是能实现对pdf、doc等文件的读写操作,但要显示,目前还达不到。itext网站FAQ栏明确指出itext不能显示pdf,jacob也一样  
     
    =========================================================
    正确~
    可以看看xpdf,我也正在研究~,听说这个可以,具体说不清楚