Hi, I’m getting an exception when I try to replace a simple text on a small PDF.
This is the error:
Object reference not set to an instance of an object.
This is the code i’m using:
// Open document
Document pdfDocument = new Document(Server.MapPath(@"\test\Test1_compress.pdf"));
// Create TextAbsorber object to find all instances of the input search phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("UserName");
// Accept the absorber for all the pages
pdfDocument.Pages.Accept(textFragmentAbsorber);
// Get the extracted text fragments
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
// Loop through the fragments
foreach (TextFragment textFragment in textFragmentCollection) {
textFragment.TextState.FontSize = 30;
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Blue);
textFragment.Text = "CarlosJCT";
}
pdfDocument.Save(Server.MapPath(@"\test\test1_2.pdf"));
The error is in the line:
textFragment.Text = “CarlosJCT”;Test1_compress.pdf (68.7 KB)