Convert PDF to text
Contents
[
Hide
]
Try online. You can check the quality of Aspose.PDF conversion and view the results online at this link products.aspose.app/pdf/conversion/pdf-to-txt
Convert PDF page to text file
You can convert PDF document to TXT file with Aspose.PDF for Android via Java. You should use Visit method of TextAbsorber class for resolve this task.
The following code snippet explains how to extract the texts from the particular pages.
public void convertPDFPagesToTXT() {
// Open document
try {
document = new Document(inputStream);
} catch (Exception e) {
resultMessage.setText(e.getMessage());
return;
}
TextAbsorber ta = new TextAbsorber();
int[] pages = new int[] { 1, 3, 4 };
for (int page : pages) {
ta.visit(document.getPages().get_Item(page));
}
File txtFileName = new File(fileStorage, "PDF-to-Text.txt");
// Save the extracted text in text file
BufferedWriter writer;
try {
writer = new BufferedWriter(new FileWriter(txtFileName));
writer.write(ta.getText());
writer.close();
}
catch (Exception e) {
resultMessage.setText(e.getMessage());
return;
}
resultMessage.setText(R.string.success_message);
}