国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Java word轉(zhuǎn)為html 兩種方式

這篇具有很好參考價(jià)值的文章主要介紹了Java word轉(zhuǎn)為html 兩種方式。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

滴滴滴上重點(diǎn)。。。

方式一:使用apache提供的工具包poi,poi使用的是4.1.2版本

? ?缺點(diǎn):對字體樣式處理不精確;wmf公式圖片部分轉(zhuǎn)換不精確,本文檔只支持doc格式

? ?優(yōu)點(diǎn):轉(zhuǎn)換速度相對很快,本地也方便調(diào)試

方式二:使用libreoffice,使用的是7.5版本

? ?地址:下載 LibreOffice | LibreOffice 簡體中文官方網(wǎng)站 - 自由免費(fèi)的辦公套件

? ?Linux安裝libreoffice案例:linux centos7工具安裝之 libreOffice篇 libreOffice安裝教程_centos7 安裝libreoffice_the_bog的博客-CSDN博客

? ?缺點(diǎn):轉(zhuǎn)換速度相對慢

? ?優(yōu)點(diǎn):字體樣式十分精確,本文檔只支持doc,docx等等。轉(zhuǎn)換pdf等相關(guān)命令百度獲取

廢話不多說直接上代碼?。?!

方式一代碼實(shí)現(xiàn):

? 相關(guān)jar包地址:

 <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi</artifactId>
      <version>4.1.2</version>
    </dependency>

    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi-scratchpad</artifactId>
      <version>4.1.2</version>
    </dependency>

    <dependency>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi-ooxml</artifactId>
      <version>4.1.2</version>
    </dependency>
  <dependency>
      <groupId>org.jsoup</groupId>
      <artifactId>jsoup</artifactId>
      <version>1.9.2</version>
    </dependency>
    <dependency>
      <groupId>org.apache.xmlgraphics</groupId>
      <artifactId>batik-codec</artifactId>
      <version>1.7</version>
    </dependency>
    <dependency>
      <groupId>net.arnx</groupId>
      <artifactId>wmf2svg</artifactId>
      <version>0.9.5</version>
    </dependency>
package cn.hls.winner.winner_problem_manage.utils;

import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.converter.PicturesManager;
import org.apache.poi.hwpf.converter.WordToHtmlConverter;
import org.apache.poi.hwpf.usermodel.PictureType;
import org.apache.poi.util.IOUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.multipart.MultipartFile;
import org.w3c.dom.Document;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * @author lhz
 * @description TODO
 * @date 2023/9/18 10:14
 */
public class Word2003Util {

    private static final Logger logger = LoggerFactory.getLogger(Word2003Util.class);


    /**
     *
     * @param multipartFile  上傳的文件
     * @param htmlFile       html上傳路徑
     * @param htmlFileImgUrl html圖片上傳路徑
     * @param wordFileUrl    word上傳路徑
     * @return
     */
    public static String word2003ToHtml(MultipartFile multipartFile, String htmlFile, String htmlFileImgUrl, String wordFileUrl) {
        // 需要判斷文件是否為doc,docx
        if (multipartFile == null) {
            return "word文檔上傳為空!";
        }
        if (multipartFile.getOriginalFilename().endsWith("docx")) {
            return "word文檔格式有誤,請上傳doc格式的!";
        }
        logger.info("***** word2003ToHtml start file:{}", multipartFile);
        //返回服務(wù)器代理地址
        String htmlUrl = "";
        //隨機(jī)命名html文件
        String uuid = UUID.randomUUID().toString();
        String htmlFileName = uuid + "." + "html";
        logger.info("==== 初始化====(htmlFileName){參數(shù)} " + htmlFileName);
        try {
            //上傳服務(wù)器的圖片本地地址
            logger.info("==== htmlFile{參數(shù)} ====" + htmlFile);
            //nginx轉(zhuǎn)發(fā)后的圖片地址
            logger.info("==== htmlFileImgUrl{參數(shù)} ====" + htmlFileImgUrl);
            //生成網(wǎng)頁的文件夾地址
            String htmlFileUrl = htmlFile + uuid + "/";
            logger.info("==== htmlFileUrl{參數(shù)} ==== " + htmlFileUrl);
            //上傳文件到服務(wù)器
            boolean flag = upload(multipartFile, wordFileUrl, uuid);
            if (!flag) {
                return "word文檔上傳失??!";
            }
            logger.info("===== word文檔上傳成功!====");
            //獲取文件名稱
            String name = multipartFile.getOriginalFilename();
            String suffix = name.substring(name.lastIndexOf("."));//.后綴名
            String filePath = wordFileUrl + uuid + suffix;
            logger.info("==== filePath ====" + filePath);
            File file = new File(filePath);
            // 1) 加載word文檔生成 HWPFDocument對象
            InputStream inputStream = new FileInputStream(file);
            HWPFDocument wordDocument = new HWPFDocument(inputStream);
            WordToHtmlConverter wordToHtmlConverter =
                    new WordToHtmlConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument());
            //圖片地址
            String fileImg = htmlFileUrl + "images/";
            File htmlFile1 = new File(htmlFileUrl);
            if (!htmlFile1.exists()) {
                //創(chuàng)建
                if (htmlFile1.mkdirs()) {
                    logger.info("創(chuàng)建" + htmlFileUrl + "成功");
                } else {
                    logger.info("創(chuàng)建" + htmlFileUrl + "成功");
                }
            }
            //html代理地址
            htmlUrl = htmlFileImgUrl + uuid + "/" + htmlFileName;
            //html生成路徑
            htmlFileName = htmlFileUrl + htmlFileName;
            logger.info("==== htmlFileName{ html ======== 輸出地址} " + htmlFileName);
            //設(shè)置圖片存放的位置
            String finalFileImg = fileImg;
            final int[] index = {1};
            //處理圖片地址
            wordToHtmlConverter.setPicturesManager(new PicturesManager() {
                public String savePicture(byte[] content, PictureType pictureType, String suggestedName, float widthInches, float heightInches) {
                    File imgPath = new File(finalFileImg);
                    if (!imgPath.exists()) {//圖片目錄不存在則創(chuàng)建
                        imgPath.mkdirs();
                    }
                    String extension = pictureType.getExtension();
                    //隨機(jī)生成圖片名稱
                    suggestedName = finalFileImg + "image" + index[0] + "." + extension;
                    File file = new File(suggestedName);
                    OutputStream os = null;
                    try {
                        os = new FileOutputStream(file);
                        os.write(content);
                        os.close();
                        //處理wmf公式圖片
//                        if (extension.equals("wmf") || extension.equals("svg")) {
//                            if (extension.equals("wmf")) {
//                                String svgFile = suggestedName.substring(0,
//                                        suggestedName.lastIndexOf(".wmf"))
//                                        + ".svg";
//                                SvgToPngUtil.wmfToSvg(suggestedName, svgFile);
//                            }
//                            String suggestedNameSVG = suggestedName.substring(0, suggestedName.lastIndexOf(".")) + ".svg";
                            String s = SvgToPngUtil.readToString(suggestedNameSVG);
                            String suggestedNamePng = suggestedName.substring(0, suggestedName.lastIndexOf(".")) + ".png";
                            SvgToPngUtil.convertToPng(s, suggestedNamePng);
                            String s1 = SvgToPngUtil.GetImageStr(suggestedNameSVG);
//                            //刪除無用圖片
                            deleteFile(suggestedNameSVG, suggestedName);
//                            suggestedName = suggestedNameSVG;
//                        }
                    } catch (FileNotFoundException e) {
                        throw new RuntimeException(e);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                    //這里可以指定word文檔中圖片的路徑。
                    String imgUlr = suggestedName.replace(htmlFile, htmlFileImgUrl);
                    index[0]++;
                    return imgUlr;
                }
            });
            wordToHtmlConverter.processDocument(wordDocument);
            Document htmlDocument = wordToHtmlConverter.getDocument();
            OutputStream outputStream = new FileOutputStream(htmlFileName);
            DOMSource domSource = new DOMSource(htmlDocument);
            StreamResult streamResult = new StreamResult(outputStream);
            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer serializer = factory.newTransformer();
            serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
            serializer.setOutputProperty(OutputKeys.INDENT, "yes");
            serializer.setOutputProperty(OutputKeys.METHOD, "html");
            serializer.transform(domSource, streamResult);
            outputStream.close();
            logger.info("===== 網(wǎng)頁樣式轉(zhuǎn)換開始 ====");
            String htmlContents = readHtml(htmlFileName);
            FileCopyUtils.copy(htmlContents.getBytes("utf-8"), new File(htmlFileName));
            logger.info("===== 網(wǎng)頁樣式轉(zhuǎn)換完成 ====");
        } catch (Exception e) {
            logger.error("word2003ToHtml====異常");
            logger.error(e.getMessage());
            throw new RuntimeException(e);
        }
        //
        return htmlUrl;
    }

    //獲取網(wǎng)頁內(nèi)容
    public static String readHtml(String htmlFileName) throws Exception {
        StringBuilder htmlContents1 = new StringBuilder();
        String htmlContents = "";
        //讀圖網(wǎng)頁內(nèi)容
        BufferedReader buf = new BufferedReader(
                new InputStreamReader(new FileInputStream(htmlFileName), "utf-8"));
        String c = "";
        while ((c = buf.readLine()) != null) {
            htmlContents1.append(c + "\n");
        }

        buf.close();
        htmlContents = htmlContents1.toString();
        htmlContents = htmlContents.replace("hyphenate:auto;font-family:Times New Roman;", "hyphenate:auto;font-family:宋體;").replace("vertical-align:text-bottom;", "vertical-align: middle;").replace("’","'").replace("&rsquo;","'");
        org.jsoup.nodes.Document document = Jsoup.parse(htmlContents);
        formatHtml(document);
        htmlContents = document.toString();
        return htmlContents;
    }

    //網(wǎng)頁字體樣式
    public static void formatHtml(org.jsoup.nodes.Document document) {
        Elements elements = document.getAllElements();
        String title = document.title();
        logger.info("==== formatHtml ====title"+title);
        for (Element element : elements) {
            if ("main".equals(element.className())) {
                continue;
            }
            if (title.contains("物理") || title.contains("數(shù)學(xué)") || title.contains("化學(xué)")) {
                if (element.hasClass("s1")) {
                    element.attr("style", "font-family:Times New Roman;" + element.attr("style"));
                }
            }
            String[] attrs = element.attr("style").split(";");
            List<String> attrList = new ArrayList();
            for (String attr : attrs) {
                if (attr.contains("font-family")) {
                    attrList.add(attr);
                }
            }
            //將<body>標(biāo)簽里的class屬性b1 b2去掉
            Elements bodys = element.getElementsByTag("body");
            for(Element body : bodys){
                System.out.println("=======className:" + body.className() + "==========");
                if("b1 b2".equals(body.className())){
                    body.attr("class","");
                }
            }
        }
    }

    public static void deleteFile(String... imgUrl) {
        for (String s : imgUrl) {
            File file = new File(s);
            try {
                if (file.isFile()) {
                    // 刪除文件
                    if (file.delete()) {
                        logger.info("刪除文件成功==== 名稱為:" + file.getName());
                    } else {
                    }
                } else {
                }
            } catch (Exception e) {
                logger.error("====== 刪除圖片失敗 ======" + e.getMessage());
                throw new RuntimeException();
            }
        }
    }


    /**
     * @param file     文件
     * @param htmlFile 文件上傳地址
     * @param fileName 文件名稱
     * @return
     */
    public static boolean upload(MultipartFile file, String htmlFile, String fileName) {
        InputStream is = null;
        OutputStream os = null;
        try {
            File file1 = new File(htmlFile);
            if (!file1.exists()) {
                file1.mkdirs();
            }
            String name = file.getOriginalFilename();
            String suffix = name.substring(name.lastIndexOf("."));//.后綴名
            is = file.getInputStream();
            os = new FileOutputStream(htmlFile + fileName + suffix);
            //數(shù)據(jù)對拷
            IOUtils.copy(is, os);
            logger.info("==== 文件寫入成功!====");
        } catch (IOException e) {
            logger.error("===== 文件上傳失敗 ====" + e.getMessage());
            return false;
        } finally {
            if (null != is) {
                try {
                    is.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if (null != os) {
                try {
                    os.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        return true;
    }
}

方式二代碼實(shí)現(xiàn)文章來源地址http://www.zghlxwxcb.cn/news/detail-788074.html

package com.hls.poi.service;


import com.hls.poi.controller.WordToHtmlController;
import org.apache.poi.util.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.util.UUID;

public class LibreOfficeCommandWordService {

    private static final Logger logger = LoggerFactory.getLogger(WordToHtmlController.class);

    /**
     * /opt/libreoffice7.5/program/soffice --headless --invisible --convert-to pdf /opt/a/1.docx --outdir /opt/a/
     * –convert-to pdf 后面的 /opt/a/1.docx 為原文件路徑
     * –outdir /opt/a/(轉(zhuǎn)換后文件存放目錄)
     * <p>
     * soffice --headless --invisible --convert-to html:HTML ffc75d91-3594-451d-a55f-a941325bc380.doc --outdir mmm
     */

    //需要根據(jù)實(shí)際情況,查找LibreOffice安裝的實(shí)際目錄,
    //Mac下是默認(rèn)安裝到/usr/local/bin,
    //CentOS下默認(rèn)安裝在/usr/bin
    private final static String sofficeDir = "/opt/libreoffice7.6/program/";

    /**
     * @param multipartFile  上傳的文件
     * @param htmlFile       html上傳路徑
     * @param htmlFileImgUrl html圖片上傳路徑
     * @param wordFileUrl    word上傳路徑
     * @param sofficeDir     libreOffice安裝地址
     * @throws Exception
     */
    public String word2html(MultipartFile multipartFile, String htmlFile, String htmlFileImgUrl, String wordFileUrl, String sofficeDir) throws Exception {
        try {
            logger.info("exec command:[{}]\noutput: [{}]", "進(jìn)入word2pdf{} 方法");
            // 需要判斷文件是否為doc,docx
            if (multipartFile == null) {
                return "word文檔上傳為空!";
            }
            //返回服務(wù)器代理地址
            String htmlUrl = "";
            //隨機(jī)命名html文件
            String uuid = UUID.randomUUID().toString();
            String htmlFileName = uuid + "." + "html";
            logger.info("==== 初始化====(htmlFileName){參數(shù)} " + htmlFileName);
            //上傳服務(wù)器的圖片本地地址
            logger.info("==== htmlFile{參數(shù)} ====" + htmlFile);
            //nginx轉(zhuǎn)發(fā)后的圖片地址
            logger.info("==== htmlFileImgUrl{參數(shù)} ====" + htmlFileImgUrl);
            //生成網(wǎng)頁的文件夾地址
            String htmlFileUrl = htmlFile + uuid + "/";
            logger.info("==== htmlFileUrl{參數(shù)} ==== " + htmlFileUrl);
            //上傳文件到服務(wù)器
            boolean flag = upload(multipartFile, wordFileUrl, uuid);
            if (!flag) {
                return "word文檔上傳失?。?;
            }
            logger.info("===== word文檔上傳成功!====");
            //獲取文件名稱
            String name = multipartFile.getOriginalFilename();
            String suffix = name.substring(name.lastIndexOf("."));//.后綴名
            //上傳后word文檔路徑   /home/winnersoft/date/tomcat/html-root/office/word/8ea8aec0-7fb5-4fbc-b73c-6f0e47b2857e.doc
            String inPath = wordFileUrl + uuid + suffix;
            logger.info("==== inPath ====" + inPath);
            if (!new File(inPath).exists()) {
                return "word文檔不存在!";
            }
            //圖片地址
            File htmlFile1 = new File(htmlFileUrl);
            if (!htmlFile1.exists()) {
                //創(chuàng)建
                if (htmlFile1.mkdirs()) {
                    logger.info("創(chuàng)建" + htmlFileUrl + "成功");
                } else {
                    logger.info("創(chuàng)建" + htmlFileUrl + "成功");
                }
            }
            //html代理地址  //http://172.18.222.25:82/office/html/8ea8aec0-7fb5-4fbc-b73c-6f0e47b2857e/8ea8aec0-7fb5-4fbc-b73c-6f0e47b2857e.html
            htmlUrl = htmlFileImgUrl + uuid + "/" + htmlFileName;
            //html生成路徑    /home/winnersoft/date/tomcat/html-root/office/html/af7ac82f-71bc-498c-8866-8bf7ef325345/
            htmlFileName = htmlFileUrl;
            logger.info("==== outPath{ html ======== 輸出地址} " + htmlFileName);
            //設(shè)置圖片存放的位置
//        String command = String.format("%s/soffice --convert-to pdf:writer_pdf_Export %s --outdir %s", sofficeDir, inPath, outPath);
            String command = String.format("%s/soffice --headless --invisible --convert-to html:HTML %s --outdir %s", sofficeDir, inPath, htmlFileName);
            logger.info("command==================================" + command);
            String output = this.executeCommand(command);
            logger.info("exec command:[{}]\noutput: [{}]", command, output);
            return htmlUrl;
        } catch (IOException e) {
            logger.error("io異常"+e.getMessage());
            throw new RuntimeException(e);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    protected String executeCommand(String command) throws IOException, InterruptedException {
        logger.info("executeCommand{} 執(zhí)行轉(zhuǎn)化");
        StringBuffer output = new StringBuffer();
        Process p;
        p = Runtime.getRuntime().exec(command);
        p.waitFor();
        try (
                InputStreamReader inputStreamReader = new InputStreamReader(p.getInputStream(), "UTF-8");
                BufferedReader reader = new BufferedReader(inputStreamReader)
        ) {
            String line = "";
            while ((line = reader.readLine()) != null) {
                output.append(line + "\n");
            }
        }
        // 銷毀子進(jìn)程
        p.destroy();
        return output.toString();
    }

    /**
     * @param file     文件
     * @param htmlFile 文件上傳地址
     * @param fileName 文件名稱
     * @return
     */
    public static boolean upload(MultipartFile file, String htmlFile, String fileName) {
        InputStream is = null;
        OutputStream os = null;
        try {
            File file1 = new File(htmlFile);
            if (!file1.exists()) {
                file1.mkdirs();
            }
            String name = file.getOriginalFilename();
            String suffix = name.substring(name.lastIndexOf("."));//.后綴名
            is = file.getInputStream();
            os = new FileOutputStream(htmlFile + fileName + suffix);
            //數(shù)據(jù)對拷
            IOUtils.copy(is, os);
            logger.info("==== 文件寫入成功!====");
        } catch (IOException e) {
            logger.error("===== 文件上傳失敗 ====" + e.getMessage());
            return false;
        } finally {
            if (null != is) {
                try {
                    is.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if (null != os) {
                try {
                    os.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        return true;
    }
}

到了這里,關(guān)于Java word轉(zhuǎn)為html 兩種方式的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Java將PDF文件轉(zhuǎn)為Word文檔

    Java將PDF文件轉(zhuǎn)為Word文檔

    一、創(chuàng)建Springboot Maven項(xiàng)目 二、導(dǎo)入依賴信息 三、創(chuàng)建Main類 代碼如下: 效果展示:

    2024年02月11日
    瀏覽(20)
  • java中使用POI將word轉(zhuǎn)為PDF時(shí)無法顯示文字

    背景: 在windos上本地調(diào)試時(shí)使用POI將word轉(zhuǎn)為PDF時(shí), PDF無法顯示文字的原因以及解決方案: 原因1 :字體不存在問題, word中使用的字體在系統(tǒng)(windows或者linux)上一定要已經(jīng)安裝, 否則PDF無法顯示文字, 將需要的字體下載下來, 復(fù)制到 1) windows 的 C:WindowsFonts 文件夾下面, 然后重啟機(jī)器

    2023年04月10日
    瀏覽(52)
  • 如何通過Java代碼將 PDF文檔轉(zhuǎn)為 HTML格式

    如何通過Java代碼將 PDF文檔轉(zhuǎn)為 HTML格式

    雖然PDF文件適合用于打印和發(fā)布,但不適合所有類型的文檔。例如,包含復(fù)雜圖表和圖形的文檔可能無法在PDF中呈現(xiàn)得很好。但是HTML文件可以在任何可運(yùn)行瀏覽器的計(jì)算機(jī)上進(jìn)行閱讀并顯示。并且HTML還具有占用服務(wù)器資源較小,便于搜索引擎收錄的特點(diǎn)。那么今天這篇文章就

    2024年02月05日
    瀏覽(20)
  • Python - 將RTF文件轉(zhuǎn)為Word 、PDF、HTML格式

    Python - 將RTF文件轉(zhuǎn)為Word 、PDF、HTML格式

    RTF也稱富文本格式,是一種具有良好兼容性的文檔格式,可以在不同的操作系統(tǒng)和應(yīng)用程序之間進(jìn)行交換和共享。有時(shí)出于不同項(xiàng)目的需求,我們可能需要將RTF文件轉(zhuǎn)為其他格式。本文將介如何通過簡單的Python代碼將RTF文件轉(zhuǎn)換為Word Doc/Docx、PDF、HTML格式。 ? 實(shí)現(xiàn)步驟如下:

    2024年02月19日
    瀏覽(48)
  • Java如何將字符串轉(zhuǎn)為數(shù)字int(三種方式)

    如何將java字符串轉(zhuǎn)換為數(shù)字 對知識永遠(yuǎn)只有學(xué)無止境。 第一種 第二種 第三種 注意:這三種的轉(zhuǎn)換區(qū)別在哪里呢?對知識應(yīng)該敬畏。 第一種是將字符串,轉(zhuǎn)換成一個(gè)數(shù)字的對象,兩個(gè)相同的數(shù)字進(jìn)行轉(zhuǎn)換。 結(jié)果:不相等 第二種:多次的解析,最終的得到結(jié)果,可以用 “

    2024年02月13日
    瀏覽(67)
  • java實(shí)現(xiàn)word轉(zhuǎn)html

    現(xiàn)有的需求是前端導(dǎo)入word文件,然后需要在瀏覽器上展示出來,實(shí)現(xiàn)方案是將前端導(dǎo)入的word轉(zhuǎn)成html的形式,再輸出給前端,廢話不多說,直接上代碼. 需要用到的依賴 ?代碼實(shí)現(xiàn) 注意事項(xiàng) 1.這個(gè)方法只支持docx結(jié)尾的文檔,doc文檔大同小異,如果有需要可以嘗試自己寫一下 2.和圖片上

    2024年02月15日
    瀏覽(19)
  • Java將Word轉(zhuǎn)換成PDF

    Java將Word轉(zhuǎn)換成PDF

    最近項(xiàng)目需要做在線預(yù)覽文檔功能,要求對word文檔后臺轉(zhuǎn)為pdf,遇到了很多問題,因此記錄一下。 網(wǎng)上有很多將Word轉(zhuǎn)換成PDF的方式,這里我試了幾種比較簡單的方式:POI、aspose、spire和documents4j。 POI是Apache下的一個(gè)Java類庫,可以幫助我們實(shí)現(xiàn)Java與各種Office格式文件的互相轉(zhuǎn)

    2024年02月08日
    瀏覽(21)
  • java html轉(zhuǎn)word、pdf(包含圖片)

    maven依賴 核心代碼 maven依賴 核心代碼 Base64ImgReplacedElementFactory類

    2024年02月07日
    瀏覽(27)
  • java將word轉(zhuǎn)換成pdf,并去除水印
  • java 使用documents4j將XML轉(zhuǎn)為pdf文件的方式

    java 使用documents4j將XML轉(zhuǎn)為pdf文件的方式

    通過spire.doc.free將word轉(zhuǎn)換成PDF時(shí)存在缺陷:只能獲取前3頁。獲取全文另外需支付費(fèi)用。 使用documents4j,documents4j會保留原word文件中更多的樣式,如修訂模式下的差異化字體顏色、文檔右側(cè)修訂記錄等。 1.引入Pom 2.??xml2pdf方法如下,xmlpath是xml文件地址,pdfPath是生成的pdf地址

    2024年02月21日
    瀏覽(20)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包