Last active
September 28, 2020 19:41
-
-
Save soreana/4c9e1a60e7ca8471ede779c91a72b86c to your computer and use it in GitHub Desktop.
Java PDF Reader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
<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