In this article, we’re going to explain how to extract text from a Pdf file in Java. An overview of content: Extract All Text from a Pdf Read/Extract Text from a Specific Rectangle Area in a Pdf Page Read/Extract Text using SimpleTextExtractionStrategy The Pdf library we need: Spire.PDF for Java The example Pdf file: Sample Code Imported Namespaces import com.spire.pdf.*; import com.spire.pdf.exporting.text.SimpleTextExtractionStrategy; import java.awt.geom.Rectangle2D; import java.io.*; Read/Extract All Text from a Pdf //Instantiate a PdfDocument object PdfDocument pdf = new PdfDocument(); //Load the Pdf file pdf.loadFromFile("Additional.pdf"); StringBuilder sb= new StringBuilder(); //Extract text from every page of the Pdf for (PdfPageBase page: (Iterable<PdfPageBase>) pdf.getPages()) { sb.append(page.extractText(true)); } try { //Write the text into a .txt file FileWrite...
A blog about Microsoft Office and PDF document development using .NET and Java.