在线文档查阅-OpenOffice+SWFTool+FlexPaper

最近项目上打算做一个文档的在线浏览器(主要是文本文件),但是考虑到有可能有word,excel之类文档也需要在线浏览,所以采取:文档--->PDF---->swf(前端FlexPaper浏览)

这里只贴一下文档转PDF,PDF转swf的代码

文档转PDF使用OpenOffice和以下几个jar包实现


主要java代码:

// 获取转换配置
		DefaultDocumentFormatRegistry formatReg = new DefaultDocumentFormatRegistry();
		DocumentFormat format = formatReg.getFormatByFileExtension(fileExt);
		// 不存在的文档类型全部使用txt的format,默认的txt Format使用utf8编码
		if (format == null) {
			format = formatReg.getFormatByFileExtension("txt");
		}
		try {
			converter.convert(source, format, pdfFile,
					formatReg.getFormatByFileExtension("pdf"));
			pdfFile.createNewFile();
		} catch (ConnectException e) {
			e.printStackTrace();
		} catch (OpenOfficeException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
我这里默认扩展名不存在的文档类型全部是纯文档类型(java,jsp文件等等),来看下txt的配置(jodconverter-2.2.2.jar 里面的document-formats.xml文件中)

 <document-format>
    <name>Plain Text</name>
    <family>Text</family>
    <mime-type>text/plain</mime-type>
    <file-extension>txt</file-extension>
    <export-options>
      <entry>
        <family>Text</family>
        <map>
          <entry>
            <string>FilterOptions</string>
            <string>UTF8,CRLF</string>
          </entry>
          <entry>
            <string>FilterName</string>
            <string>Text (encoded)</string>
          </entry>
        </map>
      </entry>
    </export-options>
    <import-options>
      <entry>
        <string>FilterOptions</string>
        <string>UTF8,CRLF</string>
      </entry>
      <entry>
        <string>FilterName</string>
        <string>Text (encoded)</string>
      </entry>
    </import-options>
  </document-format>
这里要注意的是纯文本文件需以utf-8编写,否则将导致转出来的pdf中文乱码

pdf文件转换为swf供flash播放器(FlexPaper)使用

这里使用SWFTool就可以了,区别是在windows和在linux系统下实现不一样(我这里服务器是win server2003):

windows操作系统使用:

Runtime r = Runtime.getRuntime();
Process p = r.exec(SWFTOOLS_PDF2SWF_EXE_PATH + " " + pdfPath + " -o " + swfFile.getPath() + " -T 9 -s flashversion=9");
p.waitFor();
swfFile.createNewFile();
其实就是在Java中执行一条cmd命令来转换






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值