使用 Tika 从大型 pdf 中提取文本 [英] Extract text from a large pdf with Tika

查看:42
本文介绍了使用 Tika 从大型 pdf 中提取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从一个大的 pdf 中提取文本,但我只得到了第一页,我需要将所有文本传递给一个字符串变量.

I try to extract text from a large pdf, but i only get the first pages, i need all text to will be passed to a string variable.

这是代码

public class ParsePDF {
    public static void main(String args[]) throws Exception {


    try {

      File file = new File("C:/vlarge.pdf");

      String content = new Tika().parseToString(file);

      System.out.println("The Content: " + content);

        }
        catch (Exception e) {
          e.printStackTrace();
        }
    }
}

推荐答案

来自 Javadocs:

为了避免不可预知的过多内存使用,返回的字符串包含最多只能从 getMaxStringLength() 中提取的第一个字符输入文件.使用 setMaxStringLength(int) 方法来调整这个限制.

To avoid unpredictable excess memory use, the returned string contains only up to getMaxStringLength() first characters extracted from the input document. Use the setMaxStringLength(int) method to adjust this limitation.

调用 setMaxStringLength(-1) 将禁用此限制.

Calling setMaxStringLength(-1) will disable this limit.

这篇关于使用 Tika 从大型 pdf 中提取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆