kkFiewView代码分析(九)——office插件相关

2021SC@SDUSC

 

目录

pdf文件形式设置

html文件形式设置

txt文件形式设置


         上一篇介绍了officePluginManager对office组件的管理,这一篇继续介绍项目中另外一个类OfficePluginExtendFormatRegistry,原作者对该类的描述重写DefaultDocumentFormatRegistry类的原因是因为要添加一些自定义行为,比如字符编码等。

        该类的主要方法都依靠jodconverter提供的接口实现,jodconverter是一种Java OpenDocument转换器,能够转换不同格式的文档,它依赖于Apachea OpenOffice或 LibreOffice ,它为OpenDocument和Microsoft Office提供了最好的免费导入/导出的过滤器。它自动支持OpenOffice和LibreOffice提供的所有转换。jodconverter的应用很广泛,在本个项目中,它作为一个Java类库,嵌入到整体应用程序提供服务。

        整个类只有一个初始化方法,public OfficePluginExtendFormatRegistry() {},类中为24种不同的文件格式设置了不同的存储参数,以pdf为例就设计了四种不同的storeProperties。接下来以pdf文件形式、html文件形式和txt形式为例分析一些详细的方法。

pdf文件形式设置

针对pdf设置了四次存储属性,分别是TEXT、SPREADSHEET、PRESENTATION、DRAWING。

        DocumentFormat pdf = new DocumentFormat("Portable Document Format", "pdf", "application/pdf");
        pdf.setStoreProperties(DocumentFamily.TEXT, Collections.singletonMap("FilterName", "writer_pdf_Export"));
        pdf.setStoreProperties(DocumentFamily.SPREADSHEET, Collections.singletonMap("FilterName", "calc_pdf_Export"));
        pdf.setStoreProperties(DocumentFamily.PRESENTATION, Collections.singletonMap("FilterName", "impress_pdf_Export"));
        pdf.setStoreProperties(DocumentFamily.DRAWING, Collections.singletonMap("FilterName", "draw_pdf_Export"));
        addFormat(pdf);

html文件形式设置

针对html文件设置了三次存储属性,分别是TEXT、SPREADSHEET和PRESENTATION、

        DocumentFormat html = new DocumentFormat("HTML", "html", "text/html");
        html.setInputFamily(DocumentFamily.TEXT);
        html.setStoreProperties(DocumentFamily.TEXT, Collections.singletonMap("FilterName", "HTML (StarWriter)"));
        Map<String,Object> htmlLoadAndStoreProperties = new LinkedHashMap<>();
        htmlLoadAndStoreProperties.put("FilterName", "HTML (StarCalc)");
        htmlLoadAndStoreProperties.put("FilterOptions", "utf8");
        html.setStoreProperties(DocumentFamily.SPREADSHEET, htmlLoadAndStoreProperties);
        html.setStoreProperties(DocumentFamily.PRESENTATION, Collections.singletonMap("FilterName", "impress_html_Export"));
        addFormat(html);

txt文件形式设置

FilterOptions,设置为utf8。这里的意思应该是只对UTF-8格式的文本文件进行转换。

        DocumentFormat txt = new DocumentFormat("Plain Text", "txt", "text/plain");
        txt.setInputFamily(DocumentFamily.TEXT);
        Map<String,Object> txtLoadAndStoreProperties = new LinkedHashMap<>();
        txtLoadAndStoreProperties.put("FilterName", "Text (encoded)");
        txtLoadAndStoreProperties.put("FilterOptions", "utf8");
        txt.setLoadProperties(txtLoadAndStoreProperties);
        txt.setStoreProperties(DocumentFamily.TEXT, txtLoadAndStoreProperties);
        addFormat(txt);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值