当前位置: 首页 > news >正文

磐安县住和城乡建设局网站好的网站分享

磐安县住和城乡建设局网站,好的网站分享,福建省高速公路建设管理网站,网站打开的速度慢转自:https://www.ibm.com/developerworks/cn/java/l-java-tips/ 感谢作者发布的文章用 jacob其实 jacob 是一个 bridage#xff0c;连接 java 和 com 或者 win32 函数的一个中间件#xff0c;jacob 并不能直接抽取 word,excel 等文件#xff0c;需要自己写 dll 哦…转自:https://www.ibm.com/developerworks/cn/java/l-java-tips/     感谢作者发布的文章用 jacob其实 jacob 是一个 bridage连接 java 和 com 或者 win32 函数的一个中间件jacob 并不能直接抽取 word,excel 等文件需要自己写 dll 哦不过已经有为你写好的了就是 jacob 的作者一并提供了。下载了 jacob 并放到指定的路径之后 (dll 放到 path,jar 文件放到 classpath)就可以写你自己的抽取程序了下面是一个简单的例子importjava.io.File;import com.jacob.com.*;import com.jacob.activeX.*;/*** Title: pdf extraction* Description: email:chrismatrix.org.cn* Copyright: Matrix Copyright (c) 2003* Company: Matrix.org.cn*authorchris*version1.0,who use this example pls remain the declare*/public classFileExtracter{public static voidmain(String[] args) {ActiveXComponent component new ActiveXComponent(Word.Application);String inFile c:\\test.doc;String tpFile c:\\temp.htm;String otFile c:\\temp.xml;boolean flag false;try{component.setProperty(Visible, new Variant(false));Object wordacc component.getProperty(document ).toDispatch();Object wordfile Dispatch.invoke(wordacc,Open, Dispatch.Method,new Object[]{inFile,new Variant(false), new Variant(true)},new int[1] ).toDispatch();Dispatch.invoke(wordfile,SaveAs, Dispatch.Method,new Object[]{tpFile,new Variant(8)}, new int[1]);Variant f new Variant(false);Dispatch.call(wordfile,Close, f);flag true;}catch(Exception e) {e.printStackTrace();}finally{component.invoke(Quit, newVariant[] {});}}}用 apache 的 poi 来抽取 wordexcel。poi 是 apache 的一个项目不过就算用 poi 你可能都觉得很烦不过不要紧这里提供了更加简单的一个接口给你下载之后放到你的 classpath 就可以了下面是如何使用它的一个例子import java.io.*;import org.textmining.text.extraction.WordExtractor;/*** Title: word extraction* Description: email:chrismatrix.org.cn* Copyright: Matrix Copyright (c) 2003* Company: Matrix.org.cn* 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 isstr.length());System.out.println(the result isstr);}}pdfbox- 用来抽取 pdf 文件下面是一个如何使用 pdfbox 抽取 pdf 文件的例子importorg.pdfbox.pdmodel.PDdocument importorg.pdfbox.pdfparser.PDFParser;import java.io.*;importorg.pdfbox.util.PDFTextStripper;importjava.util.Date;/*** Title: pdf extraction* Description: email:chrismatrix.org.cn* Copyright: Matrix Copyright (c) 2003* Company: Matrix.org.cn*authorchris*version1.0,who use this example pls remain the declare*/public classPdfExtracter{publicPdfExtracter(){}public String GetTextFromPdf(String filename) throwsException{String tempnull;PDdocument nbsppdfdocument null;FileInputStream isnewFileInputStream(filename);PDFParser parser newPDFParser( is );parser.parse();pdfdocument nbspparser.getPDdocument );ByteArrayOutputStream out newByteArrayOutputStream();OutputStreamWriter writer newOutputStreamWriter( out );PDFTextStripper stripper newPDFTextStripper();stripper.writeText(pdfdocument getdocument ), writer );writer.close();byte[] contents out.toByteArray();String tsnewString(contents);System.out.println(the string length iscontents.length\n);returnts;}public static voidmain(String args[]){PdfExtracter pfnewPdfExtracter();PDdocument nbsppdfdocument nbsp null;try{String tspf.GetTextFromPdf(c:\\a.pdf);System.out.println(ts);}catch(Exception e){e.printStackTrace();}}}抽取支持中文的 pdf 文件xpdfxpdf 是一个开源项目我们可以调用他的本地方法来实现抽取中文 pdf 文件。按照 readme 放好中文的 patch就可以开始写调用本地方法的 java 程序了下面是一个如何调用的例子import java.io.*;/*** Title: pdf extraction* Description: email:chrismatrix.org.cn* Copyright: Matrix Copyright (c) 2003* Company: Matrix.org.cn*authorchris*version1.0,who use this example pls remain the declare*/public classPdfWin {publicPdfWin() {}public static void main(String args[]) throwsException{String PATH_TO_XPDFC:\\Program Files\\xpdf\\pdftotext.exe;String filenamec:\\a.pdf;String[] cmd new String[] { PATH_TO_XPDF, -enc, UTF-8, -q, filename, -};Process pRuntime.getRuntime().exec(cmd);BufferedInputStream bis newBufferedInputStream(p.getInputStream());InputStreamReader reader new InputStreamReader(bis, UTF-8);StringWriter out newStringWriter();char [] buf new char[10000];intlen;while((len reader.read(buf)) 0) {//out.write(buf, 0, len);System.out.println(the length islen);}reader.close();String tsnewString(buf);System.out.println(the str ists);}}
http://www.zqtcl.cn/news/562368/

相关文章:

  • 手机销售培训网站wordpress案例插件
  • 滨江道做网站公司wordpress 花瓣网
  • 如何建网站快捷方式软件开发做平台
  • 常见的静态网页深圳罗湖企业网站优化
  • 做网站一天赚多少钱外贸网站建设排名
  • 一个大型网站建设得多少钱百度成都总部
  • 网站制作公司汉狮网络手机版网站优化
  • 铜川做网站logo 图标 设计
  • 如何做网站的注册页面南京宣传片公司有哪些
  • 中国建设机械教育协会网站网站建设中html中关于图片显示的标签有哪些
  • 网站过期后dede减肥网站源码
  • 营销型 手机网站网站建设方案后期服务
  • 怎么做一个个人网站建网站的八个步骤
  • 淘宝导购网站模版上海网站推广软件
  • 做影视网站引流湖北响应式网站建设费用
  • 网站统计cnzz网站空间有哪些
  • 泉州微信网站开发公司wordpress头像解决
  • 湛江网站建设皆选小罗24专业网站建设 福田
  • 厦门哪些做鲜花的网站门户网站开发设计报告
  • asp.net网站设计分工天津网站开发贴吧
  • 做多语言网站教程南宁vi设计公司
  • 百度联盟 网站备案wordpress 吾爱破解
  • 山西省建设厅网站首页网络营销推广为什么效果不好
  • 建材做网站好吗长沙做网站微联讯点不错
  • 建设小型网站分类门户网站系统
  • 文化馆网站数字化建设介绍138ip地址查询网站
  • 卖汽车的网站怎么做的建设服装网站的论文
  • 网络推广哪个网站好网站建设最低多少钱
  • 怎么在自己电脑做网站北京赛车网站开发
  • 门户网站内容wordpress上下页