PDDocument document = null; try { document = PDDocument.load( "C:\\thesis\\fileread sim.pdf" ); if( document.isEncrypted() ) { try { document.decrypt( "" ); } catch( InvalidPasswordException e ) { System.err.println( "Error: Document is encrypted with a password." ); System.exit( 1 ); } } PDFTextStripper stripper = new PDFTextStripper(); stripper.setSortByPosition( true ); stripper.setStartPage( startPage ); stripper.setEndPage( endPage ); System.out.println("Text: " + stripper.getText(document));