Extract Text From Stamps
Contents
[
Hide
]
Extract Text from Stamp Annotations
Aspose.PDF for PHP via Java lets you extract text from stamp annotations. In order to extract text from Stamp Annotations in a PDF, the following steps can be used.
- Load the PDF document
- Get the desired page of the document
- Create a new instance of the StampAnnotation class
- Create a new instance of the AnnotationSelector class and pass the stamp annotation to it
- Accept the annotation selector on the page
- Get the selected stamp annotations
- Create a new instance of the TextAbsorber class
- Get the first stamp annotation
- Get the normal appearance of the stamp annotation
- Visit the appearance using the text absorber
- Get the extracted text from the text absorber
- Close the document
$responseData = "";
$document = new Document($inputFile);
$page = $document->getPages()->get_Item(1);
$stampAnnotation = new StampAnnotation($document);
$annotationSelector = new AnnotationSelector($stampAnnotation);
$page->accept($annotationSelector);
$stampAnnotations = $annotationSelector->getSelected();
$textAbsorber = new TextAbsorber();
$stampAnnotation = $stampAnnotations->get(0);
$appearance = $stampAnnotation->getNormalAppearance();
$textAbsorber->visit($appearance);
$responseData = java_values($textAbsorber->getText());
$document->close();