项目有个需求,需要在微信企业号中word文档在线浏览。找了好多资料,没找到什么好办法。无奈只能转换成图片显示。

准备
jacob.jar
office2010
这个只能是word转pdf (找过好多插件可以word直接转图片,但是效果不好)

/*** word转换pdf* @param sfileName 源文件路径* @param toFileName 目标文件路径* @param folderPath 目标文件所在文件夹路径*/public static void wordToPDF(String sfileName, String toFileName, String folderPath) {System.out.println("启动Word...");ActiveXComponent app = null;Dispatch doc = null;try {app = new ActiveXComponent(ISystemConstant.DICTIONARY_FILE_CONVERT_WORD_START);app.setProperty(ISystemConstant.DICTIONARY_FILE_CONVERT_WORD_PROPERTY_01, new Variant(false));Dispatch docs = app.getProperty(ISystemConstant.DICTIONARY_FILE_CONVERT_WORD_PROPERTY_02).toDispatch();// doc = Dispatch.call(docs, "Open" , sourceFile).toDispatch();doc = Dispatch.invoke(docs,ISystemConstant.DICTIONARY_FILE_CONVERT_WORD_PROPERTY_03,Dispatch.Method,new Object[] { sfileName, new Variant(false),new Variant(true) }, new int[1]).toDispatch();System.out.println("打开文档..." + sfileName);System.out.println("转换文档到PDF..." + toFileName);File tofile = new File(toFileName);if (tofile.exists()) {tofile.delete();}FileOperateHelper.newFolder(folderPath);// Dispatch.call(doc, "SaveAs", destFile, 17);Dispatch.invoke(doc, ISystemConstant.DICTIONARY_FILE_CONVERT_WORD_PROPERTY_04, Dispatch.Method, new Object[] {toFileName, new Variant(WDFORMATPDF) }, new int[1]);} catch (Exception e) {RmProjectHelper.logError("========Error:文档转换失败:", e);} finally {Dispatch.call(doc, ISystemConstant.DICTIONARY_FILE_CONVERT_WORD_PROPERTY_05, false);System.out.println("关闭文档");if (app != null)app.invoke(ISystemConstant.DICTIONARY_FILE_CONVERT_WORD_PROPERTY_06, new Variant[] {});// 如果没有这句话,winword.exe进程将不会关闭ComThread.Release();}
/*** 启动word进程*/public static final String DICTIONARY_FILE_CONVERT_WORD_START = "Word.Application";/*** 调用方法*/public static final String DICTIONARY_FILE_CONVERT_WORD_PROPERTY_01 = "Visible";/*** 调用方法*/public static final String DICTIONARY_FILE_CONVERT_WORD_PROPERTY_02 = "Documents";/*** 调用方法*/public static final String DICTIONARY_FILE_CONVERT_WORD_PROPERTY_03 = "Open";/*** 调用方法 */public static final String DICTIONARY_FILE_CONVERT_WORD_PROPERTY_04 = "SaveAs";/*** 调用方法 关闭*/public static final String DICTIONARY_FILE_CONVERT_WORD_PROPERTY_05 = "Close";/*** 调用方法 退出*/public static final String DICTIONARY_FILE_CONVERT_WORD_PROPERTY_06 = "Quit";

pdf有了 接下来转换图片

public static List<String> pdfToImage(String pdfPath,String imgPath, String rootPath) throws IOException {  FileChannel channel = null;List<String> list = new ArrayList<String>();try {File file = new File(  pdfPath);  RandomAccessFile raf = new RandomAccessFile(file, "r");  channel = raf.getChannel();  ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel  .size()); PDFFile pdffile = new PDFFile(buf);  System.out.println("页数: " + pdffile.getNumPages());  for (int i = 1; i <= pdffile.getNumPages(); i++) {  // draw the first page to an image  PDFPage page = pdffile.getPage(i);  // get the width and height for the doc at the default zoom  Rectangle rect = new Rectangle(0, 0, (int) page.getBBox()  .getWidth(), (int) page.getBBox().getHeight());  // generate the image  Image img = page.getImage(rect.width, rect.height, // width &  // height  rect, // clip rect  null, // null for the ImageObserver  true, // fill background with white  true // block until drawing is done  );  BufferedImage tag = new BufferedImage(rect.width, rect.height,  BufferedImage.TYPE_INT_RGB);  tag.getGraphics().drawImage(img, 0, 0, rect.width, rect.height,  null); list.add(imgPath + i + ISystemConstant.DICTIONARY_IMAGE_SUFFIX);FileOutputStream out = new FileOutputStream(  rootPath + imgPath  + i + ISystemConstant.DICTIONARY_IMAGE_SUFFIX); // 输出到文件流  JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);  encoder.encode(tag); // JPEG编码  out.close(); }  return list;}finally{channel.close();}

手机浏览器显示word文档相关推荐

  1. Linux命令行如何编辑word文档,在Linux平台下用命令行工具显示Word文档

    在Linux平台下用命令行工具显示Word文档 ·Antiword ·Catdoc ·wvWare[@more@] Viewing Word files at the command line Wed ...

  2. 使用文件流的形式在浏览器下载word文档

    一.使用文件流的形式在浏览器下载word文档 String path = "http://172.16.228.130:7300/document/d9dd1ec7e72d4fc6a9e50 ...

  3. 通过WebBrowser显示Word文档的方法

    通过以下代码可以实现利用WebBrowser来显示word文档 public partial class Form1 : Form{public Form1(){InitializeComponent ...

  4. 在IE浏览器中如何直接显示word文档

    //开始读取           if(myRead.Read()   ==   true)           {             Byte[]   Buffer   =   (Byte[] ...

  5. html5在线显示word文档,JS实现获取word文档内容并输出显示到html页面示例

    本文实例讲述了js实现获取word文档内容并输出显示到html页面.分享给大家供大家参考,具体如下: title var w = new activexobject('word.application ...

  6. C# 读取并显示word文档中的内容

    我想将信道模型的介绍以及分析的情况,都在C#的程序设计中进行实现.然后就想到了将word文档直接显示到窗体中,并且有滚动条可以拉动进行查看.搜集了一些资料之后找到了合适的方法--利用RichTextB ...

  7. 安卓手机如何将Word文档转换成PDF

    相信大家大会去打印机去打印文件,我们大部分都是拿着Word文档去打印,但是Word文档 受软件版本的限制,它会出现格式错乱或者排版不正确. 但是PDF文档就不会受软件版本以及电脑字体的影响而发生排版. ...

  8. 重复显示Word文档表格标题行

     当Word文档中表格的内容多于一页时,我们可以设置标题行重复,使其反复出现在每一页表格的首行或数行,这样更便于表格内容的理解,也能满足某些时候表格打印的要求. 步骤: 1.如果表格的第一行作为标题行 ...

  9. 浏览器显示XML文档

    在网站后台管理介面上,有一个预览铵钮,管理员能点一点,把XML的文档显示于浏览器上. 这个XML文档如下: HTML Markup: 去.aspx.cs写ButtonPreview_Click事件: ...

最新文章

  1. 我酸了!又是别人家公司!百度新年发 U 奖金鼓励员工
  2. SQL关键字转换大写核心算法实现
  3. gulp html 模块化,使用Gulp如何实现静态网页模块化具体怎么做?
  4. SpringBoot中使用FastJson解析Json数据
  5. unity3d 地面印花_unity怎么实现挖掘泥土?
  6. 【笔记】高效率但却没用过的一些numpy函数
  7. Eagle 画板-拼板-输出Gerber到SeeedStudio打样过程笔记
  8. 读取xls格式的文件
  9. IC卡管理系统(Java基础)
  10. Swift中MVP、Moya、模型设计
  11. 工业相机概述-选型事项-生产厂家汇总
  12. html5 三国杀,OL还更新HTML5吗?不更新不充值了
  13. 文件服务协议:cifs/nfs 简介
  14. Python学习demo01 创建牌->洗牌->发牌->整理牌
  15. 汇编创建Win32窗体
  16. Laravel图片合成
  17. python小游戏实现代码
  18. 如何理解“技术问题”
  19. Memblaze 联手PMC推出用于超大规模数据中心的高性能PCIe SSD
  20. 【论文阅读-3】生成模型——变分自编码器(Variational Auto-Encoder,VAE)

热门文章

  1. 字幕助手 FastTitle 0.0.3 版本发布
  2. MongoDB设置账号密码
  3. 安卓手机上最好的3个epub阅读器
  4. SDIO - 1bit / 4bit V2.0 协议深度解析-简单易懂协议详解
  5. 第一篇:瑞吉外卖项目概述
  6. 瑞吉外卖项目 基于spring Boot+mybatis-plus开发 超详细笔记,有源码链接
  7. HEXOFontmin
  8. python 生成词云
  9. 在“芯片庭院”培育一颗多核异构 RISC-V SOC种子
  10. 【强化学习】Playing Atari with Deep Reinforcement Learning (2013)