一、前言

目前支持:

  1. wordhtml
  2. docdocx
  3. htmlword
  4. htmlpdf
  5. excelpdf
  6. wordjpeg
  7. wordpng
  8. markdownhtml

二、项目地址

https://gitee.com/zhengqingya/file-convert-util

三、部分代码

具体代码请查看项目示例

1、主要调用工具类

@Slf4j
public class MyFileConvertUtil {/*** `word` 转 `html`** @param wordBytes:*            word字节码* @return: html文件字节码数据* @author : zhengqing* @date : 2020/11/23 16:21*/public static byte[] wordBytes2HtmlBytes(byte[] wordBytes) {return Word2HtmlUtil.wordBytes2HtmlBytes(wordBytes);}/*** `word` 转 `html`** @param wordBytes:*            word字节码* @return: html文件内容* @author : zhengqing* @date : 2020/11/23 16:21*/public static String wordBytes2HtmlStr(byte[] wordBytes) {byte[] htmlBytes = Word2HtmlUtil.wordBytes2HtmlBytes(wordBytes);return new String(htmlBytes);}/*** `word` 转 `html`** @param wordBytes:*            word字节码* @param htmlFilePath:*            html文件路径* @return: html文件数据* @author : zhengqing* @date : 2020/11/23 16:21*/public static File wordBytes2HtmlFile(byte[] wordBytes, String htmlFilePath) {return Word2HtmlUtil.wordBytes2HtmlFile(wordBytes, htmlFilePath);}/*** `doc` 转 `docx`** @param docBytes:*            doc文件字节码* @return: 生成的`docx`文件字节码* @author : zhengqing* @date : 2020/11/24 11:26*/public static byte[] docBytes2DocxBytes(byte[] docBytes) {return Doc2DocxUtil.docBytes2DocxBytes(docBytes);}/*** `doc` 转 `docx`** @param docBytes:*            doc文件字节码* @param docxFilePath:*            待生成的的`docx`文件路径* @return: 生成的`docx`文件数据* @author : zhengqing* @date : 2020/11/24 11:26*/public static File docBytes2DocxFile(byte[] docBytes, String docxFilePath) {return Doc2DocxUtil.docBytes2DocxFile(docBytes, docxFilePath);}/*** `html` 转 `word` 【 注:本地图片不支持显示!!! 需转换成在线图片 】** @param htmlBytes:*            html字节码* @return: word文件字节码* @author : zhengqing* @date : 2020/11/24 11:52*/public static byte[] htmlBytes2WordBytes(byte[] htmlBytes) {return Htm2WordlUtil.htmlBytes2WordBytes(htmlBytes);}/*** `html` 转 `word` 【 注:本地图片不支持显示!!! 需转换成在线图片 】** @param html:*            html内容* @return: word文件字节码* @author : zhengqing* @date : 2020/11/24 11:52*/public static byte[] html2WordBytes(String html) {return Htm2WordlUtil.htmlBytes2WordBytes(html.getBytes());}/*** `html` 转 `word` 【 注:本地图片不支持显示!!! 需转换成在线图片 】*** @param htmlBytes:*            html字节码* @param wordFilePath:*            待生成的word文件路径* @return: word文件信息* @author : zhengqing* @date : 2020/11/23 16:04*/public static File htmlBytes2WordFile(byte[] htmlBytes, String wordFilePath) {return Htm2WordlUtil.htmlBytes2WordFile(htmlBytes, wordFilePath);}/*** `html` 转 `pdf`** @param htmlBytes:*            html字节码* @return: 生成的`pdf`字节码* @author : zhengqing* @date : 2020/11/24 11:26*/public static byte[] htmlBytes2PdfBytes(byte[] htmlBytes) {return Html2PdfUtil.htmlBytes2PdfBytes(htmlBytes);}/*** `html` 转 `pdf`** @param htmlBytes:*            html文件数据* @param pdfFilePath:*            待生成的`pdf`文件路径* @return: 生成的`pdf`文件数据* @author : zhengqing* @date : 2020/11/24 11:26*/public static File htmlBytes2PdfFile(byte[] htmlBytes, String pdfFilePath) {return Html2PdfUtil.htmlBytes2PdfFile(htmlBytes, pdfFilePath);}/*** `excel` 转 `pdf`** @param excelBytes:*            html字节码* @return: 生成的`pdf`文件流* @author : zhengqing* @date : 2020/11/24 11:26*/public static byte[] excelBytes2PdfBytes(byte[] excelBytes) {return Excel2PdfUtil.excelBytes2PdfBytes(excelBytes);}/*** `excel` 转 `pdf`** @param excelBytes:*            excel文件字节码* @param pdfFilePath:*            待生成的`pdf`文件路径* @return: 生成的`Pdf`文件数据* @author : zhengqing* @date : 2020/11/24 11:26*/public static File excelBytes2PdfFile(byte[] excelBytes, String pdfFilePath) {return Excel2PdfUtil.excelBytes2PdfFile(excelBytes, pdfFilePath);}/*** `word` 转 `jpeg`** @param wordBytes:*            word字节码数据* @return: 图片字节码数据列表* @author : zhengqing* @date : 2020/11/24 11:52*/public static List<byte[]> wordBytes2JpegBytes(byte[] wordBytes) {return Word2JpegUtil.wordBytes2JpegBytes(wordBytes);}/*** `word` 转 `jpeg`** @param wordBytes:*            word字节码数据* @param imgRootPath:*            生成图片根路径* @return: 图片字节码数据列表* @author : zhengqing* @date : 2020/11/24 11:52*/public static List<File> wordBytes2JpegFileList(byte[] wordBytes, String imgRootPath) {return Word2JpegUtil.wordBytes2JpegFileList(wordBytes, imgRootPath);}/*** `word` 转 `png`** @param wordBytes:*            word字节码数据* @return: 图片字节码数据列表* @author : zhengqing* @date : 2020/11/24 11:52*/@SneakyThrows(Exception.class)public static List<byte[]> wordBytes2PngBytes(byte[] wordBytes) {return Word2PngUtil.wordBytes2PngBytes(wordBytes);}/*** `word` 转 `png`** @param wordBytes:*            word字节码数据* @param imgRootPath:*            生成图片路径* @return: 图片字节码数据列表* @author : zhengqing* @date : 2020/11/24 11:52*/public static List<File> wordBytes2PngFileList(byte[] wordBytes, String imgRootPath) {return Word2PngUtil.wordBytes2PngFileList(wordBytes, imgRootPath);}}
2、测试类
@RunWith(SpringRunner.class)
@SpringBootTest
public class AppTest {private final String WORD_FILE_PATH = Constants.DEFAULT_FOLDER_TMP + "/test.doc";private final String HTML_FILE_PATH = Constants.DEFAULT_FOLDER_TMP + "/test.html";private final String EXCEL_FILE_PATH = Constants.DEFAULT_FOLDER_TMP + "/test.xlsx";private final String MD_FILE_PATH = Constants.DEFAULT_FOLDER_TMP + "/test.md";@Testpublic void testWord2Html() throws Exception {File htmlFile = MyFileConvertUtil.wordBytes2HtmlFile(MyFileUtil.readBytes(WORD_FILE_PATH),Constants.DEFAULT_FOLDER_TMP_GENERATE + "/test.html");System.out.println(htmlFile);}@Testpublic void testHtml2Word() throws Exception {File wordFile = MyFileConvertUtil.htmlBytes2WordFile(MyFileUtil.readBytes(HTML_FILE_PATH),Constants.DEFAULT_FOLDER_TMP_GENERATE + "/test.doc");System.out.println(wordFile);}@Testpublic void testDoc2Docx() throws Exception {File docxFile = MyFileConvertUtil.docBytes2DocxFile(MyFileUtil.readBytes(WORD_FILE_PATH),Constants.DEFAULT_FOLDER_TMP_GENERATE + "/test.docx");System.out.println(docxFile);}@Testpublic void testHtml2Pdf() throws Exception {File pdfFile = MyFileConvertUtil.htmlBytes2PdfFile(MyFileUtil.readBytes(HTML_FILE_PATH),Constants.DEFAULT_FOLDER_TMP_GENERATE + "/test-html.pdf");System.out.println(pdfFile);}@Testpublic void testExcel2Pdf() throws Exception {File pdfFile = MyFileConvertUtil.excelBytes2PdfFile(MyFileUtil.readBytes(EXCEL_FILE_PATH),Constants.DEFAULT_FOLDER_TMP_GENERATE + "/test-excel.pdf");System.out.println(pdfFile);}@Testpublic void testWord2Jpg() throws Exception {byte[] wordFileBytes = MyFileUtil.readBytes(WORD_FILE_PATH);List<File> jpgFileList =MyFileConvertUtil.wordBytes2JpegFileList(wordFileBytes, Constants.DEFAULT_FOLDER_TMP_GENERATE);System.out.println(jpgFileList);}@Testpublic void testWord2Png() throws Exception {byte[] wordFileBytes = MyFileUtil.readBytes(WORD_FILE_PATH);List<File> pngFileList =MyFileConvertUtil.wordBytes2PngFileList(wordFileBytes, Constants.DEFAULT_FOLDER_TMP_GENERATE);System.out.println(pngFileList);}@Test // 【 注:转换格式不是太完善,存在一定问题! 】public void testMarkdown2Html() throws Exception {FileFactory.produce(new File(MD_FILE_PATH), Constants.DEFAULT_FOLDER_TMP_GENERATE + "/test-md.html");}}

今日分享语句:
生活从来都不容易,总是伴随着一个又一个的坎坷和挑战。
聪明的人,懂得调节自己的情绪,不会被外在事物轻易地影响自己的心情,看淡世间沧桑,内心安然无恙。
说到底,很多人都毁在了自寻烦恼上。如果学会这三点,你将会快乐很多。

Java 文件转换工具类(word,html,excel,pdf,md,jpeg,png互转)相关推荐

  1. java 对象 转换 工具类_Java中excel与对象的互相转换的通用工具类编写与使用(基于apache-poi-ooxml)...

    通用excel与对象相互转换的工具类 前言:最近开发需要一个Excel批量导入或者导出的功能,之前用过poi-ooxml开发过一个导入的工具类,正好蹭着这次机会,把工具类的功能进行完善. 使用说明: ...

  2. PDF转换工具类(byte[]转PDF并生成文件)

    PDF转换工具类(byte[]转PDF并生成文件) 对html转为标准的xhtml public byte[] transferHtml2XHtml(byte[] html){Tidy tidy = ...

  3. 自定义java对象转换工具类

    背景 项目中经常有VO.PO.DTO等之间转换,由于apache工具类中BeanUtils.copyProperties及Json序列化反序列化方式转换性能比较低(阿里巴巴规范检查有提示不建议采用). ...

  4. Java金额转换工具类

    package com.healthy.prms.common.util;import java.math.BigDecimal;/*** @ClassName: RMBUtils* @Descrip ...

  5. JAVA日期转换工具类

    java中经常会用到日期的转换,所有自己整理了一套日期转换的工具类,方便使用. 首先导入 <dependency><groupId>joda-time</groupId& ...

  6. 提高工作效率的万能Java行列转换工具类

    1.说明 有时候工作中需要动态生成列,也就是不确定的列,那么在数据库层就不是那么好操作了,可以使用java工具类来实现. 本工具类是对市面上的工具类进行加工改造,可以通用于各种情况,更加灵活,下面我来 ...

  7. java中文转换工具类

    /*** 获取中文首字母工具类** @author jiangjunjie*/ public class ChineseCharToEnUtil {/*** 转换为有声调的拼音字符串** @param ...

  8. java 时间转换工具类 yyyyMMdd HH:mm

    获取系统当前时间戳 : System.currentTimeMillis()) 获取系统当前时间任意格式,自己根据生成的格式选择性填写 /*** 获取当前时间* 把需要生成的时间格式替换一下就可以* ...

  9. Java时间转换工具类

    /*** 获取对应毫秒转换成的天 时 分 秒 ms** @author 刘子固* @dete 2022.9.27*/ public class TimeDateUtils {/*** 一秒钟1000毫 ...

最新文章

  1. oracle 加号和on,Oracle中连接与加号(+)的使用
  2. C语言打印等腰三角形
  3. HDU 5703 Desert 水题 找规律
  4. VMware虚拟机很卡~
  5. virtualenv模块使用
  6. python编程求极限_Sympy笔记一
  7. Race Condition是什么
  8. java开源代码生成器_人人开源之代码生成器(renren-generator)
  9. fs2410开发板搭建网站服务器,FS2410开发板使用步骤
  10. 用栈实现的算术表达式的运算
  11. IntelliJ IDEA 自定义注释作者名字
  12. Json与List、Map、entity的互相转化
  13. 24位真彩色图片取摸方法(用于WS2812显示)
  14. CocosCreator3.x屏幕适配
  15. 【游戏推荐】欧陆风云4 1.33.3.0 all dlc Europa Universalis 4
  16. 5个高清视频素材网站,免费下载~
  17. Joplin手机和电脑无法同步问题
  18. Java 解析线程的几种状态详解
  19. pytorch实现循环神经网络实验
  20. A Primer on Memory Consistency and Cache Coherence

热门文章

  1. matlab avi视频文件与mat文件 互相转换
  2. 解读动环监控系统架构
  3. 针对淘宝反selenium的反反爬措施详讲1-----pyautogui
  4. 理解移动语义(五)--左右值判断的常见错误
  5. 如何拍摄一次通过的计算机考试报名照片
  6. 最详细安装双系统教程(适用于uefi启动模式)
  7. B2A云集成服务 连接一次。 达到任何目标
  8. HAProxy HTTPS代理
  9. 微信android最新版本,安卓微信怎么升级为最新版微信8.0 安卓微信升级8.0方法
  10. 批量直播监测,开播自动下载、分割、上传投稿至bilibili