To read a PDF file, you must have export box1.7.1.jar and fontbox1.7.1.jar. You can go to the official website or my resources. The following code
Import java. io. fileWriter; import java. io. IOException; import java. io. printWriter; import org.apachedomainbox. pdmodel. PDDocument; import org.apachedomainbox. util. extends textstripper; public class Mytest {public static String getText (String file) {String s = ""; String pdffile = file; PDDocument upload Doc = null; try {export Doc = PDDocument. load (pdffile); extends textstripper stripper = new extends textstripper (); s = stripper. getTe Xt (release DOC);} catch (IOException e) {e. printStackTrace ();} finally {try {if (release Doc! = Null) {Doc. close () ;}} catch (IOException e) {e. printStackTrace () ;}} return s;} public static void toTextFile (String doc, String filename) throws Exception {String pdffile = doc; PDDocument doc = null; PrintWriter pw = null; try {export Doc = PDDocument. load (pdffile); inclutextstripper stripper = new inclutextstripper (); pw = new PrintWriter (new FileWriter (filename); stripper. writeText (writable doc, pw);} catch (IOException e) {e. printStackTrace ();} finally {try {if (pw! = Null) {pw. close () ;}if (batch Doc! = Null) {Doc. close () ;}} catch (IOException e) {e. printStackTrace () ;}} public static void main (String [] args) {try {String SC = getText ("Enter the path of the PDF file to be converted here"); System. out. print (SC); toTextFile ("Enter the path of the PDF file to be converted", "Path of the txt file to be saved");} catch (Exception e) {e. printStackTrace ();}}}