软航Office文档控件 就有这个功能 具体的你可以看看 二次开发文档。
解决方案 »
- 说出你觉得最好用的工具?
- 本来好好的,一段时间没用后,Myeclipse中无法起来tomcat
- 怎样给内部类传递一个外部参数
- mysql + hibernate 出现的中文乱码问题
- 添加JSTL1.1时web-inf下没有tld文件
- tomcat4.1.31数据源上问题 (100)
- 使用hibernate3.0不能用中文查询请大家帮帮忙啊!
- 大家怎么理解Struts的
- struts标签的使用问题!!!!!!!!!!!!!!!!!!!!!!!!!!!!!(在线等)
- javaee 判断用户状态值是否为true,数据库status值是1但是user.isStatus取出来都是false.
- weblogic问题,求助。。。
- s2sh问题
很多office插件都有这个功能
System.out.println("==============================");
System.out.println("Extract word start:===========");
File file = new File(path);
String returnString = "";
InputStream is;
try {
is = new FileInputStream(file);
WordExtractor extractor = new WordExtractor();
returnString = extractor.extractText(is);
System.out.println("Extract word end:===========");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return returnString;
}
将内容写入到pdf中public static void write(String content, String filePath) throws IOException{
System.out.println("==============================");
System.out.println("Write to pdf start:===========");
final int margin = 10;
// create the file
File file = new File(filePath);
if(!file.exists()){
Document doc = null;
FileOutputStream fos = null;
PdfWriter pdfWriter = null;
try {
BaseFont bFont = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", false);
Font font = new Font(bFont);
font.setSize(8);
doc = new Document(PageSize.A4, margin, margin, margin, margin);
fos = new FileOutputStream(file);
pdfWriter = PdfWriter.getInstance(doc, fos);
doc.open();
doc.addTitle(filePath.replace("D:\\", ""));
doc.add(new Paragraph(content, font));
System.out.println("Write to pdf end:===========");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
if(doc != null){
doc.close();
}
if(pdfWriter != null){
pdfWriter.close();
}
if(fos != null){
fos.close();
}
}
}
}
希望对你有用哈,我也是以前做测试的时候写的了……
这个也不兼容吧,而且要在win下面,还要安装注册adobe