• 大小: 5.51MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-31
  • 语言: 其他
  • 标签: Spring  boot  在线预览  

资源简介

Spring boot 在线预览办公文件(doc、docx、xls、xlsx、pdf等),转化效果个人觉得比较理想

资源截图

代码片段和文件信息

//
// JODConverter - Java OpenDocument Converter
// Copyright 2004-2012 Mirko Nasato and contributors
//
// JODConverter is Open Source software you can redistribute it and/or
// modify it under either (at your option) of the following licenses
//
// 1. The GNU Lesser General Public License v3 (or later)
//    -> http://www.gnu.org/licenses/lgpl-3.0.txt
// 2. The Apache License Version 2.0
//    -> http://www.apache.org/licenses/LICENSE-2.0.txt
//
package org.artofsolving.jodconverter;

import static org.artofsolving.jodconverter.office.OfficeUtils.SERVICE_DESKTOP;
import static org.artofsolving.jodconverter.office.OfficeUtils.cast;
import static org.artofsolving.jodconverter.office.OfficeUtils.toUnoProperties;
import static org.artofsolving.jodconverter.office.OfficeUtils.toUrl;

import java.io.File;
import java.util.Map;

import org.artofsolving.jodconverter.office.OfficeContext;
import org.artofsolving.jodconverter.office.OfficeException;
import org.artofsolving.jodconverter.office.OfficeTask;

import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XStorable;
import com.sun.star.io.IOException;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.XComponent;
import com.sun.star.task.ErrorCodeIOException;
import com.sun.star.util.CloseVetoException;
import com.sun.star.util.XCloseable;

public abstract class AbstractConversionTask implements OfficeTask {

    private final File inputFile;
    private final File outputFile;

    public AbstractConversionTask(File inputFile File outputFile) {
        this.inputFile = inputFile;
        this.outputFile = outputFile;
    }

    protected abstract Map getLoadProperties(File inputFile);

    protected abstract Map getStoreProperties(File outputFile XComponent document);

    public void execute(OfficeContext context) throws OfficeException {
        XComponent document = null;
        try {
            document = loadDocument(context inputFile);
            modifyDocument(document);
            storeDocument(document outputFile);
        } catch (OfficeException officeException) {
            throw officeException;
        } catch (Exception exception) {
            throw new OfficeException(“conversion failed“ exception);
        } finally {
            if (document != null) {
                XCloseable closeable = cast(XCloseable.class document);
                if (closeable != null) {
                    try {
                        closeable.close(true);
                    } catch (CloseVetoException closeVetoException) {
                        // whoever raised the veto should close the document
                    }
                } else {
                    document.dispose();
                }
            }
        }
    }

    private XComponent loadDocument(OfficeContext context File inputFile) throws OfficeException {
        if (!inputFile.exists()) {
            throw new OfficeException(“input document not found“);

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-01-29 15:55  file-online-preview\
     文件         438  2018-01-22 09:18  file-online-preview\.gitignore
     目录           0  2018-01-30 13:29  file-online-preview\.idea\
     文件          11  2018-01-29 15:50  file-online-preview\.idea\.name
     文件         805  2018-01-29 15:55  file-online-preview\.idea\compiler.xml
     文件         306  2018-01-29 15:55  file-online-preview\.idea\encodings.xml
     目录           0  2018-01-31 14:57  file-online-preview\.idea\inspectionProfiles\
     目录           0  2018-01-29 15:55  file-online-preview\.idea\libraries\
     文件         495  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__antlr_antlr_2_7_7.xml
     文件         608  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__ch_qos_logback_logback_classic_1_1_11.xml
     文件         587  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__ch_qos_logback_logback_core_1_1_11.xml
     文件         539  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__com_beust_jcommander_1_12.xml
     文件         555  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__com_fasterxml_classmate_1_3_4.xml
     文件         677  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_0.xml
     文件         635  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_core_2_8_10.xml
     文件         663  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__com_fasterxml_jackson_core_jackson_databind_2_8_10.xml
     文件         736  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__com_fasterxml_jackson_dataformat_jackson_dataformat_yaml_2_8_10.xml
     文件         536  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__com_github_junrar_junrar_0_7.xml
     文件         532  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__com_google_guava_guava_19_0.xml
     文件         579  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__com_jayway_jsonpath_json_path_2_2_0.xml
     文件         585  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__com_thoughtworks_xstream_xstream_1_3_1.xml
     文件         733  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml
     文件         547  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__commons_cli_commons_cli_1_1.xml
     文件         547  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__commons_cli_commons_cli_1_2.xml
     文件         576  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__commons_codec_commons_codec_1_10.xml
     文件         624  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__commons_httpclient_commons_httpclient_3_1.xml
     文件         536  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__commons_io_commons_io_1_4.xml
     文件         536  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__commons_io_commons_io_2_4.xml
     文件         605  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__commons_logging_commons_logging_1_1_1.xml
     文件         619  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__commons_logging_commons_logging_api_1_1.xml
     文件         495  2018-01-29 15:55  file-online-preview\.idea\libraries\Maven__dom4j_dom4j_1_6_1.xml
............此处省略1380个文件信息

评论

共有 条评论