• 文件转换,简简单单,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;
    
        }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

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

      /**
         * 只是单纯的文字转换,没有任何的格式
         *
         * @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;
    
        }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40

    需要的依赖

     <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>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

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

  • 相关阅读:
    已解决selenium.common.exceptions.TimeoutException: Message: script timeout
    一个Linux主机巡检脚本
    Termux设置自启动
    『忘了再学』Shell基础 — 29、AWK内置变量
    易基因|宏病毒组测序技术介绍
    https部署(nginx代理) keycloak ,js加载不出来的问题
    人工神经网络算法的应用,人工智能神经网络算法
    2M大小的PDF文档上传到LangChain-ChatGLM知识图谱中,大致需要的时间
    一体化步进电机在全自动影像测量仪的应用
    目标检测算法——收藏|小目标检测解决方案(三)
  • 原文地址:https://blog.csdn.net/wenquan19960602/article/details/134497550