Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchUse Apache PDFBox’s PDFTextStripper to extract a PDF’s text, then write the result to a .txt file with an explicit charset such as UTF-8. The key choices are handling passwords and extraction permissions, and deciding whether to sort text by page position to improve reading order.
Convert a PDF to TXT with PDFBox
Add Apache PDFBox to your Java project, then load the PDF, check whether extraction is permitted, extract the text, and write it to a file. The code below uses PDFBox’s current Loader API and closes the document automatically:
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
public class PdfToText {
public static void main(String[] args) throws Exception {
Path input = Path.of("input.pdf");
Path output = Path.of("output.txt");
try (PDDocument document = Loader.loadPDF(input.toFile())) {
if (!document.getCurrentAccessPermission().canExtractContent()) {
throw new IllegalStateException("PDF extraction permission is denied");
}
PDFTextStripper stripper = new PDFTextStripper();
stripper.setSortByPosition(true);
String text = stripper.getText(document);
Files.writeString(output, text, StandardCharsets.UTF_8);
}
}
}
PDFTextStripper extracts text while ignoring much of the PDF’s formatting, and getText(document) returns the extracted content as a string. PDFTextStripper API documentation describes its behavior and methods.
The example’s imports use the Loader API. Use the loading method documented for the PDFBox version in your project; older releases may have different loading APIs. The official PDFBox examples demonstrate loading a document, checking its access permission, extracting text, and closing the document.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →#1 Best Overall
- LIGHTWEIGHT AND FOLDABLE STRUCTURE: Foldable design (30x6x8cm) and lightweight (1000g) make it portable for travel or home use. Compact shape fits perfectly on your workbench without taking up much space
- SIMPLE CONNECTION: Works with USB connection without the need for additional programs for quick installation. Simple controls make it easy to operate both beginners and regular users with regular size papers
- QUICK DOCUMENT PROCESSING: Automatically scan suggestions one page per second, greatly increase productivity. Ideal for workplaces, schools, legal/financial areas where large capacity is required
- TEXT CONVERSION TECHNOLOGY: Smart OCR function works in over 200 languages, changes scanned files to editable text for easy storage and editing Seamless digital conversion of paper documents improves workflow
- EXCELLENT IMAGEING: Equipped with a 16MP clear camera, this portable document scanner produces crisp, accurate images of documents and keeps important content intact. Perfect for striking scans of contracts, receipts and books
Choose the text reading order
PDFs are laid out as graphics, so their internal content-stream order may not match the order a person would read the page. By default, PDFBox follows content-stream order. Calling stripper.setSortByPosition(true) requests sorting by page position, from left to right and top to bottom. The PDFBox FAQ notes that some multi-column layouts work better with sorting disabled.
Try both settings on representative pages when extracting a document with columns, sidebars, or complex layouts. Check whether headings and paragraphs stay in the intended sequence; positional sorting is an option, not a guarantee of perfect reading order.
Rank #2
- PORTABLE SCANNER FOR USE ON-THE-GO — The fastest and lightest mobile single-sheet-fed compact document scanner in its class¹
- QUICK DOCUMENT SCANNING ― This Epson ultra-fast scanner scans a single page as quickly as 5.5 seconds²; Windows and Mac compatible
- VERSATILE PAPER HANDLING ― Portable scanner scans documents up to 8.5 x 72 in; Also easily digitizes receipts and ID cards to make accounting, bookkeeping, and organizing simpler
- INTUITIVE, HIGH-SPEED SOFTWARE — Epson ScanSmart Software³ is a smart tool allowing you to easily scan, review, and save; Stay organized easily with the help of this Epson scanner
- EASY SETUP — USB-powered connect to your computer for quick and simple scanning; No batteries or external power supply required to operate portable document scanner; Standard Connectivity: USB 2.0
Handle passwords and extraction permissions
The code checks document.getCurrentAccessPermission().canExtractContent() before extracting. If this returns false, the example throws an exception instead of silently writing text. PDFBox also documents that getText cannot process an encrypted document unless it has been opened appropriately.
For a password-protected PDF, load it using the password-aware method supported by your PDFBox version. The command-line tool also provides a password option, documented in the PDFBox command-line documentation. Do not assume that being able to open a file means its permissions allow text extraction.
Rank #3
- Amazing image clarity and detail — 4800 dpi optical resolution (1), ideal for photo enlargements
- Epson ScanSmart software included (4) — easily scan photos, artwork, illustrations, books, documents and more
- One-touch scanning (2) — scan in fewer steps with easy-to-use buttons (2)
- Restore color to faded photos — with one click, Easy Photo Fix technology makes it simple
- Scan books and photo albums — high-rise, removable lid
Why the TXT output may be empty or garbled
- The PDF may contain only page images.
PDFTextStripperextracts an existing text layer; it does not document an OCR step. If the pages are scans with no extractable text, use an OCR process separately. - The document may be encrypted. Open it appropriately with its password before calling
getText. - Extraction may be disallowed. Check
canExtractContent()and handle a denied permission explicitly. - Reading order may not match the visual page. Compare the default order with
setSortByPosition(true), especially for columns.
Extract text from the command line
For a quick check or a batch workflow, PDFBox provides an ExtractText command-line tool. Its documented form is:
java -jar pdfbox-app-2.y.z.jar ExtractText [OPTIONS] <inputfile> [Text file]
The tool can write to a text file or the console, set an encoding such as UTF-8, accept a password, and select page-related options. See the PDFBox command-line documentation for the available options for your version.
Quick Recap
Rank #4
- FAST DOCUMENT SCANNING — Document scanner with feeder allows you to speed through stacks with a 50-sheet Auto Document Feeder (ADF); Efficient office scanner to help you scan more productively
- INTUITIVE, HIGH-SPEED SOFTWARE — Quickly scan with this desktop document scanner; Epson ScanSmart Software lets you easily preview scans, email files, upload to the cloud, and more; Plus, automatic file naming saves even more time
- SEAMLESS INTEGRATION — Easily incorporate your data into most document management software with the included TWAIN driver; Office document scanner integrates seamlessly with business workflows
- EASY SHARING — Duplex scanner allows you to scan straight to email or popular cloud storage2 services like Dropbox, Evernote, Google Drive, and OneDrive for simple storage and sharing
- SIMPLE FILE MANAGEMENT — Scanner allows the creation of searchable PDFs with Optical Character Recognition (OCR) and convert scans to editable Word or Excel files effortlessly; Designed for home and office document scanning
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

