TextDevice
Inheritance: java.lang.Object, com.aspose.pdf.devices.Device com.aspose.pdf.devices.PageDevice com.aspose.pdf.devices.TextDevice, com.aspose.pdf.devices.Device, com.aspose.pdf.devices.PageDevice com.aspose.pdf.devices.TextDevice, com.aspose.pdf.devices.PageDevice, com.aspose.pdf.devices.TextDevice
public final class TextDevice extends PageDevice
Represents class for converting pdf document pages into text.
The example demonstrates how to extract text on the first PDF document page. Document doc = new Document(inFile); String extractedText; ByteArrayOutputStream ms = new ByteArrayOutputStream(); try { // create text device TextDevice device = new TextDevice(); // convert the page and save text to the stream device.process(doc.getPages().get_Item(1), ms); // use the extracted text extractedText = Encoding.getUnicode().getString(ms.toByteArray()); ms.close(); } catch (IOException e) { e.printStackTrace(); } The {@code TextDevice} object is basically used to extract text from pdf page.
Constructors
| Constructor | Description |
|---|---|
| TextDevice | Initializes a new instance of the {@code TextDevice} with the Raw text formatting mode and Unicode text encoding. |
| TextDevice | Initializes a new instance of the {@code TextDevice} with the Raw text formatting mode and Unicode text encoding. |
| TextDevice | Initializes a new instance of the {@code TextDevice} with the Raw text formatting mode and Unicode text encoding. |
| TextDevice | Initializes a new instance of the {@code TextDevice} with the Raw text formatting mode and Unicode text encoding. |
| TextDevice | Initializes a new instance of the {@code TextDevice} with the Raw text formatting mode and Unicode text encoding. |
| TextDevice | Initializes a new instance of the {@code TextDevice} with the Raw text formatting mode and Unicode text encoding. |
Methods
| Method | Description |
|---|---|
| getEncoding | Gets encoding of extracted text. |
| getEncodingInternal | Gets encoding of extracted text. |
| getExtractionOptions | Gets text extraction options. |
| process | Convert page and save it as text stream. The example demonstrates how to extract text on the first PDF document page. Document doc = new Document(inFile); String extractedText; ByteArrayOutputStream ms = new ByteArrayOutputStream(); // create text device TextDevice device = new TextDevice(); // convert the page and save text to the stream device.process(doc.getPages().get_Item(1), ms); // use the extracted text extractedText = Encoding.getUnicode().getString(ms.toByteArray()); ms.close(); |
| processInternal | Convert page and save it as text stream. |
| setEncoding | Sets encoding of extracted text. |
| setEncodingInternal | Sets encoding of extracted text. |
| setExtractionOptions | Sets text extraction options. |
TextDevice
public TextDevice()
Initializes a new instance of the {@code TextDevice} with the Raw text formatting mode and Unicode text encoding.
TextDevice
Initializes a new instance of the {@code TextDevice} with the Raw text formatting mode and Unicode text encoding.
TextDevice
Initializes a new instance of the {@code TextDevice} with the Raw text formatting mode and Unicode text encoding.
TextDevice
Initializes a new instance of the {@code TextDevice} with the Raw text formatting mode and Unicode text encoding.
TextDevice
Initializes a new instance of the {@code TextDevice} with the Raw text formatting mode and Unicode text encoding.
TextDevice
Initializes a new instance of the {@code TextDevice} with the Raw text formatting mode and Unicode text encoding.
getEncoding
public Charset getEncoding()
Gets encoding of extracted text.
Returns: Charset element
The example demonstrates how to represent extracted text in UTF-8 encoding. Document doc = new Document(inFile); String extractedText; // create text device TextDevice device = new TextDevice(java.nio.charset.Charset.forName(“UTF-8”)); // convert the page and save text to the stream device.process(doc.getPages().get_Item(1), outFile);
getEncodingInternal
public TextEncodingInternal getEncodingInternal()
Gets encoding of extracted text.
Returns: TextEncodingInternal element
The example demonstrates how to represent extracted text in UTF-8 encoding. Document doc = new Document(inFile); String extractedText; // create text device TextDevice device = new TextDevice(java.nio.charset.Charset.forName(“UTF-8”)); // convert the page and save text to the stream device.process(doc.getPages().get_Item(1), outFile);
getExtractionOptions
public TextExtractionOptions getExtractionOptions()
Gets text extraction options.
Returns: TextExtractionOptions element
The example demonstrates how to extracted text in raw order. Document doc = new Document(inFile); String extractedText; // create text device TextDevice device = new TextDevice(new TextExtractionOptions(TextExtractionOptions.TextFormattingMode.Raw)); // convert the page and save text to the stream device.process(doc.getPages().get_Item(1), outFile);
process
Convert page and save it as text stream.
The example demonstrates how to extract text on the first PDF document page. Document doc = new Document(inFile); String extractedText; ByteArrayOutputStream ms = new ByteArrayOutputStream(); // create text device TextDevice device = new TextDevice(); // convert the page and save text to the stream device.process(doc.getPages().get_Item(1), ms); // use the extracted text extractedText = Encoding.getUnicode().getString(ms.toByteArray()); ms.close();
processInternal
Convert page and save it as text stream.
setEncoding
Sets encoding of extracted text.
setEncodingInternal
Sets encoding of extracted text.
setExtractionOptions
Sets text extraction options.