Hi,
We are using Aspose PDF for .Net evaluation version and we are facing few issues. We are trying to change the foreground color of text in a pdf using position and for some text the color is not changing properly. For those text, the TextFragments count is returning as 0. Can you please look into the below code and help us to solve the issue.
Document pdfDocument = new Document(dataDir + "Festive Schedule.pdf");
List<LocationRepository> repository = new List<LocationRepository>();
LocationRepository locationRepository;
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(@".", new TextSearchOptions(true));
for (int i = 1; i <= pdfDocument.Pages.Count; i++)
{
pdfDocument.Pages[i].Accept(textFragmentAbsorber);
//get the extracted text fragments
textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach (TextFragment textFragment in textFragmentCollection)
{
foreach (TextSegment textSegment in textFragment.Segments)
{
locationRepository = new LocationRepository();
locationRepository.letter = textSegment.Text;
locationRepository.LLX = (float)textSegment.Rectangle.LLX;
locationRepository.LLY = (float)textSegment.Rectangle.LLY;
locationRepository.URX = (float)textSegment.Rectangle.URX;
locationRepository.URY = (float)textSegment.Rectangle.URY;
repository.Add(locationRepository);
}
}
for (int i = 0; i < repository.Count; i++)
{
TextFragmentAbsorber absorber = new TextFragmentAbsorber(repository[i].letter);
absorber.TextSearchOptions.LimitToPageBounds = true;
absorber.TextSearchOptions.Rectangle = new Aspose.Pdf.Rectangle((float)repository[i].LLX, (float)repository[i].LLY, (float)repository[i].URX, (float)repository[i].URY);
pdfDocument.Pages.Accept(absorber);
TextFragmentCollection textFragmentCollection = absorber.TextFragments;
foreach (TextFragment textFragment in textFragmentCollection)
{
foreach (TextSegment textSegment in textFragment.Segments)
{
textSegment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Green);
}
}
Regards,
Sreevidya