Search code examples
javaapache-tika

Tika returning empty string


I am using Apache Tika 1.14 and pdf box 2.0.5. When I try to extract the content from a pdf document, it is returning empty string.

import java.io.File;
import java.io.IOException;

import org.apache.tika.Tika;
import org.apache.tika.exception.TikaException;

public class Test {
    public static void main(String args[]) throws IOException, TikaException{
        String filePath = "sample.pdf";

        Tika tika = new Tika();
        String content = tika.parseToString(new File(filePath));

        System.out.println(content);
    }
}

Following are the maven dependencies I am using.

<!-- https://mvnrepository.com/artifact/org.apache.tika/tika-core -->
    <dependency>
        <groupId>org.apache.tika</groupId>
        <artifactId>tika-core</artifactId>
        <version>1.14</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox -->
    <dependency>
        <groupId>org.apache.pdfbox</groupId>
        <artifactId>pdfbox</artifactId>
        <version>2.0.5</version>
    </dependency>

Solution

  • You need to add 'tika-parsers' library to your project. Add following dependency and retry.

    <!-- https://mvnrepository.com/artifact/org.apache.tika/tika-parsers -->
    <dependency>
        <groupId>org.apache.tika</groupId>
        <artifactId>tika-parsers</artifactId>
        <version>1.14</version>
    </dependency>