当前位置: 首页 > article >正文

文件转换,简简单单,pdf转word,不要去找收费的了,自己学了之后免费转,之后就复制粘贴就ok了

先上一个链接pdf转word文件转换

接口层


    @PostMapping("pdfToWord")

    public String  pdfToWord(@RequestParam("file") MultipartFile file) throws IOException {

        String fileName = FileExchangeUtil.pdfToWord(file.getInputStream(),file.getName());
        return fileName;

    }

方法层-----一个方法直接搞定

  /**
     * 只是单纯的文字转换,没有任何的格式
     *
     * @param inputStream 文件流
     * @return
     */
    public static String pdfToWord(InputStream inputStream, String fileName) {
        //创建一个堆系pdf对象
        PDDocument document = null;
        FileOutputStream outputStream = null;
        if (Objects.isNull(fileName)) {
            fileName = FileExchangeUtil.getRandomString();
        }
        try {
            document = PDDocument.load(inputStream);
            PDFTextStripper stripper = new PDFTextStripper();
            //获取文本内容
            String text = stripper.getText(document);
            //创建word文档
            XWPFDocument doc = new XWPFDocument();
            XWPFParagraph p = doc.createParagraph();
            XWPFRun r = p.createRun();
            r.setText(text);
            //保存word
            outputStream = new FileOutputStream(new File("./file/"+fileName + ".docx"));
            doc.write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
            try {
                outputStream.close();
            } catch (IOException ioException) {
                ioException.printStackTrace();
                return null;
            }
            return null;
        }
        return fileName;

    }

需要的依赖

 <dependency>
            <groupId>com.alibaba.fastjson2</groupId>
            <artifactId>fastjson2</artifactId>
            <version>2.0.40</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-boot-starter -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>29.0-jre</version>
        </dependency>
        <dependency>
            <groupId>org.apache.pdfbox</groupId>
            <artifactId>pdfbox</artifactId>
            <version>2.0.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.2</version>
        </dependency>

经得起实操,不要怪我没有整理最终生成的格式,实在有些东西不好搞,只能放放了


http://www.kler.cn/news/133976.html

相关文章:

  • how to find gcc openbug
  • mysql 设置远程登录
  • 【数据结构&C++】二叉平衡搜索树-AVL树(25)
  • 系列五、怎么查看默认的垃圾收集器是哪个?
  • Java 语言关键字有哪些
  • 【0234】PgBackendStatus 记录当前postgres进程的活动状态
  • GDPU 数据结构 天码行空10
  • 华为OD机试 - 转盘寿司(Java JS Python C)
  • Springboot更新用户头像
  • 大语言模型的三阶段训练
  • vim指令
  • promise时效架构升级方案的实施及落地 | 京东物流技术团队
  • 【Go入门】 Go搭建一个Web服务器
  • 340条样本就能让GPT-4崩溃,输出有害内容高达95%?OpenAI的安全防护措施再次失效
  • 电路的基本原理
  • DeepStream--测试resnet50分类模型
  • 大数据-玩转数据-Centos7 升级JDK11
  • Flink之KeyedState
  • R语言——taxize(第二部分)
  • 036、目标检测-锚框
  • 集合的运算
  • uni-app下,页面跳转后wacth持续监听的问题处理
  • LeetCode:689. 三个无重叠子数组的最大和(dp C++)
  • Java基础- StringBuilder StringBuffer
  • Android图片涂鸦,Kotlin(1)
  • k8s_base
  • 物联网AI MicroPython学习之语法 I2C总线
  • 基于SpringBoot+Redis的前后端分离外卖项目-苍穹外卖(五)
  • 随机过程-张灏
  • java springboot 在测试类中声明临时Bean对象