Extract Text From Stamps

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.

  1. Load the PDF document
  2. Get the desired page of the document
  3. Create a new instance of the StampAnnotation class
  4. Create a new instance of the AnnotationSelector class and pass the stamp annotation to it
  5. Accept the annotation selector on the page
  6. Get the selected stamp annotations
  7. Create a new instance of the TextAbsorber class
  8. Get the first stamp annotation
  9. Get the normal appearance of the stamp annotation
  10. Visit the appearance using the text absorber
  11. Get the extracted text from the text absorber
  12. 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();