Extract Text From Stamps using C#
Contents
[
Hide
]
Extract Text from Stamp Annotations
Aspose.PDF for NET lets you extract text from stamp annotations. In order to extract text from Stamp Annotations in a PDF, the following steps can be used.
- Create a
Document
class object. - Get the desired
Annotation
from list of annotations of a page. - Define a new object of
TextAbsorber
class. - Use the TextAbsorber’s visit method to get the Text.
The following code snippet also work with Aspose.PDF.Drawing library.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ExtractText()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "ExtractStampText.pdf"))
{
Aspose.Pdf.Annotations.Annotation item = document.Pages[1].Annotations[1];
if (item is Aspose.Pdf.Annotations.StampAnnotation annot)
{
var absorber = new Aspose.Pdf.Text.TextAbsorber();
Aspose.Pdf.XForm appearance = annot.Appearance["N"];
absorber.Visit(appearance);
Console.WriteLine(absorber.Text);
}
}
}