Skip to content

Instantly share code, notes, and snippets.

@soreana
Last active September 28, 2020 19:41
Show Gist options
  • Save soreana/4c9e1a60e7ca8471ede779c91a72b86c to your computer and use it in GitHub Desktop.
Save soreana/4c9e1a60e7ca8471ede779c91a72b86c to your computer and use it in GitHub Desktop.
Java PDF Reader
/**
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.19</version>
</dependency>
*/
import java.io.File;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
public class PDF_Reader {
public static void main(String[] args) throws IOException {
//Loading an existing document
File file = new File("./file_name.pdf");
PDDocument document = PDDocument.load(file);
//Instantiate PDFTextStripper class
PDFTextStripper pdfStripper = new PDFTextStripper();
//Retrieving text from PDF document
String text = pdfStripper.getText(document);
System.out.println(txt);
//Closing the document
document.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment