如何用jsp实现在线显示pdf,doc格式文件

xieminxian 2008-12-25 11:48:48
如题,在线等,谢谢各位大虾了
...全文
2218 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
EasyPDF 2008-12-26
  • 打赏
  • 举报
回复
在web中只需要几行代码就可以
EasyPDF 2008-12-26
  • 打赏
  • 举报
回复
我们可以实现PDF的解决方案,客户端无需安装任何软件,可以严格控制文件的操作
http://www.ycanpdf.cn

qq329969959
「已注销」 2008-12-25
  • 打赏
  • 举报
回复
http://www.matrix.org.cn/resource/down/373.html 敏敏!你看看这个
_______-- 2008-12-25
  • 打赏
  • 举报
回复
类似于 google 的功能吧。
  • 打赏
  • 举报
回复
转载,本文来自http://www.matrix.org.cn/resource/article/0/120.html
很多人问到如何抽取word,excel,pdf阿。这里我总结一下抽取word,pdf的 几种方法。
1。用jacob.
其实jacob是一个bridage,连接java和com或者win32函数的一个中间件,jacob并不能直接抽取word,excel等文件,需要自己写dll哦,不过已经有为你写好的了,就是jacob的作者一并提供了。
jacob下载:http://www.matrix.org.cn/down_view.asp?id=13
下载了jacob并放到指定的路径之后(dll放到path,jar文件放到classpath),就可以写你自己的抽取程序了,下面是一个例子:
import java.io.File;
import com.jacob.com.*;
import com.jacob.activeX.*;

public class FileExtracter{

public static void main(String[] args) {

ActiveXComponent app = new ActiveXComponent("Word.Application");
String inFile = "c:\\test.doc";
String tpFile = "c:\\temp.htm";
String otFile = "c:\\temp.xml";
boolean flag = false;
try {
app.setProperty("Visible", new Variant(false));
Object docs = app.getProperty("Documents").toDispatch();
Object doc = Dispatch.invoke(docs,"Open", Dispatch.Method, new Object[]{inFile,new Variant(false), new Variant(true)}, new int[1]).toDispatch();
Dispatch.invoke(doc,"SaveAs", Dispatch.Method, new Object[]{tpFile,new Variant(8)}, new int[1]);
Variant f = new Variant(false);
Dispatch.call(doc, "Close", f);
flag = true;
} catch (Exception e) {
e.printStackTrace();
} finally {
app.invoke("Quit", new Variant[] {});
}

}
}
2。用apache的poi来抽取word,excel。
poi是apache的一个项目,不过就算用poi你可能都觉得很烦,不过不要紧,这里提供了更加简单的一个接口给你:
下载经过封装后的poi包:http://www.matrix.org.cn/down_view.asp?id=14
下载之后,放到你的classpath就可以了,下面是如何使用它的一个例子:
import java.io.*;
import org.textmining.text.extraction.WordExtractor;
/**
* <p>Title: pdf extraction</p>
* <p>Description: email:chris@matrix.org.cn</p>
* <p>Copyright: Matrix Copyright (c) 2003</p>
* <p>Company: Matrix.org.cn</p>
* @author chris
* @version 1.0,who use this example pls remain the declare
*/

public class PdfExtractor {
public PdfExtractor() {
}
public static void main(String args[]) throws Exception
{
FileInputStream in = new FileInputStream ("c:\\a.doc");
WordExtractor extractor = new WordExtractor();
String str = extractor.extractText(in);
System.out.println("the result length is"+str.length());
System.out.println("the result is"+str);
}
}

3。pdfbox-用来抽取pdf文件
但是pdfbox对中文支持还不好,先下载pdfbox:http://www.matrix.org.cn/down_view.asp?id=12
下面是一个如何使用pdfbox抽取pdf文件的例子:
import org.pdfbox.pdmodel.PDDocument;
import org.pdfbox.pdfparser.PDFParser;
import java.io.*;
import org.pdfbox.util.PDFTextStripper;
import java.util.Date;
/**
* <p>Title: pdf extraction</p>
* <p>Description: email:chris@matrix.org.cn</p>
* <p>Copyright: Matrix Copyright (c) 2003</p>
* <p>Company: Matrix.org.cn</p>
* @author chris
* @version 1.0,who use this example pls remain the declare
*/

public class PdfExtracter{

public PdfExtracter(){
}
public String GetTextFromPdf(String filename) throws Exception
{
String temp=null;
PDDocument pdfdocument=null;
FileInputStream is=new FileInputStream(filename);
PDFParser parser = new PDFParser( is );
parser.parse();
pdfdocument = parser.getPDDocument();
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter( out );
PDFTextStripper stripper = new PDFTextStripper();
stripper.writeText(pdfdocument.getDocument(), writer );
writer.close();
byte[] contents = out.toByteArray();

String ts=new String(contents);
System.out.println("the string length is"+contents.length+"\n");
return ts;
}
public static void main(String args[])
{
PdfExtracter pf=new PdfExtracter();
PDDocument pdfDocument = null;

try{
String ts=pf.GetTextFromPdf("c:\\a.pdf");
System.out.println(ts);
}
catch(Exception e)
{
e.printStackTrace();
}
}

}

4.抽取支持中文的pdf文件-xpdf
xpdf是一个开源项目,我们可以调用他的本地方法来实现抽取中文pdf文件。
下载xpdf函数包:http://www.matrix.org.cn/down_view.asp?id=15
同时需要下载支持中文的补丁包:http://www.matrix.org.cn/down_view.asp?id=16
按照readme放好中文的patch,就可以开始写调用本地方法的java程序了
下面是一个如何调用的例子:
import java.io.*;
/**
* <p>Title: pdf extraction</p>
* <p>Description: email:chris@matrix.org.cn</p>
* <p>Copyright: Matrix Copyright (c) 2003</p>
* <p>Company: Matrix.org.cn</p>
* @author chris
* @version 1.0,who use this example pls remain the declare
*/


public class PdfWin {
public PdfWin() {
}
public static void main(String args[]) throws Exception
{
String PATH_TO_XPDF="C:\\Program Files\\xpdf\\pdftotext.exe";
String filename="c:\\a.pdf";
String[] cmd = new String[] { PATH_TO_XPDF, "-enc", "UTF-8", "-q", filename, "-"};
Process p = Runtime.getRuntime().exec(cmd);
BufferedInputStream bis = new BufferedInputStream(p.getInputStream());
InputStreamReader reader = new InputStreamReader(bis, "UTF-8");
StringWriter out = new StringWriter();
char [] buf = new char[10000];
int len;
while((len = reader.read(buf))>= 0) {
//out.write(buf, 0, len);
System.out.println("the length is"+len);
}
reader.close();
String ts=new String(buf);
System.out.println("the str is"+ts);
}
}
  • 打赏
  • 举报
回复
是不是指在客户浏览器所在的机器中没有安装 Office, Adobe Reader 软件也要打开么?
  • 打赏
  • 举报
回复
什么叫在线显示啊?
lbyyy 2008-12-25
  • 打赏
  • 举报
回复
学习ing
xieminxian 2008-12-25
  • 打赏
  • 举报
回复
我要实现的功能是,在点击附件地址的时候能直接用浏览器打开附件文件并在线读取

在此基础上,用户不能下载或获取文件的路径,即只能在线阅读,不能做其他操作

谢谢了

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧