码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • PDFBOX和ASPOSE.PDF


    一、aspose.pdf

    • 文档 https://docs.aspose.com/pdf/java/

    1、按段落分段

    /**
     * docx文本按段分段
     */
    public static void main(String[] args) {
        int i = 1;
        try {
            // 打开文件流
            FileInputStream file = new FileInputStream("I:\\范文.docx");
            // 创建 Word 文档对象
            XWPFDocument doc = new XWPFDocument(file);
            // 获取所有段落
            for (XWPFParagraph para : doc.getParagraphs()) {
                // 输出段落文本
                if (!para.getText().equals("")) {
                    System.out.println(i++ + ":" + para.getText());
                }
            }
            // 关闭文件流
            file.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    2、按句子分段

    其他

    word转pdf工具之aspose

    <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-words-crack</artifactId>
            <version>21.1</version>
        </dependency>
        <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-slides</artifactId>
            <version>18.7</version>
        </dependency>
        <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-cell</artifactId>
            <version>18.9</version>
        </dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    操作pdf其它api依赖

    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>itext7-core</artifactId>
        <version>7.1.15</version>
    </dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    <dependency>
        <groupId>org.apache.pdfbox</groupId>
        <artifactId>pdfbox</artifactId>
        <version>1.8.10</version>
    </dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5

    二、PDFBOX

    1、提取pdf指定页码的数据

    public static void main(String[] args) throws IOException {
        String pdfPath = "C:\\Users\\Fushihao\\Desktop\\pdf\\test.pdf";
        int pageIndex = 4; // 指定要提取文本的页面号码
    
        // 加载 PDF 文件
        PDDocument document = PDDocument.load(new File(pdfPath));
    
        // 提取指定页面的文本
        PDFTextStripper stripper = new PDFTextStripper();
        stripper.setStartPage(pageIndex + 1);
        stripper.setEndPage(pageIndex + 1);
        String pageText = stripper.getText(document);
    
        // 输出文本到控制台
        System.out.println(pageText);
    
        // 关闭 PDF 文件
        document.close();
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    
        org.apache.pdfbox
        pdfbox
        1.8.10
    
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2、获取 PDF 字数

    public static int getPdfWords(File file) throws IOException {
        // 加载文件
        PDDocument document = PDDocument.load(file);
        PDFTextStripper stripper = new PDFTextStripper();
        // 获取字数
        String text = stripper.getText(document);
        // 关闭
        document.close();
        // 去除特殊符号返回字数
        return text.replaceAll("[\\r\\n\\t ]+", "").length();
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
  • 相关阅读:
    SQL 转置查询
    kubernetes资源管理
    身份识别与鉴权技术调研方案
    【数据结构】B树、B+树的知识点学习总结
    Vite4TSX前端版本号生成
    竞赛选题 深度学习卷积神经网络垃圾分类系统 - 深度学习 神经网络 图像识别 垃圾分类 算法 小程序
    (算法设计与分析)第四章贪心算法-第一节:贪心算法概述
    这次轮到微软炸场了;5000+AI工具调研报告 (500万字);狂打一星开喷AI聊天机器人;CMU LLM课程;AI创业的方向与时机 | ShowMeAI日报
    flutter 循环数据展示
    前端面试题之Javascript篇
  • 原文地址:https://blog.csdn.net/qq_41787812/article/details/132541776
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号