Hi Support,
We have tried to highlight the search keyword (example: “commission”) in the PDF by using below your sample code, but it shadow.hide the text and show only color on that are,.
Please refer input file “sample_INPUT” and output file “sample_OUTPUT”.
We would be happy to proceed this product if you could solve this issue and provide solutions.
Thanks & Regards,
Selvam.R
Code:
public static void Main(string[] args)
{
// The path to the documents directory.
string dataDir = Path.GetFullPath("…/…/…/Data/");
//open document
Document pdfDocument = new Document(dataDir + “sample_page_4.pdf”);
//create TextAbsorber object to find all instances of the input search phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(“commission”);
//accept the absorber for all the pages
for (int i = 1; i <= pdfDocument.Pages.Count; i++)
{
pdfDocument.Pages[i].Accept(textFragmentAbsorber);
//get the extracted text fragments
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
//PdfContentEditor editor = new PdfContentEditor();
//editor.BindPdf(dataDir + “input.pdf”);
//editor.CreateMarkup(new System.Drawing.Rectangle(87, 513, 90, 10), “”, 0, 1, System.Drawing.Color.Yellow);
//editor.Save(dataDir + “output1.pdf”);
//loop through the fragments
foreach (TextFragment textFragment in textFragmentCollection)
{
//update text and other properties
//textFragment.
//textFragment.Text = “TEXT”;
//textFragment.TextState.Font = FontRepository.FindFont(“Verdana”);
//textFragment.TextState.FontSize = 22;
//textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Blue);
textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Yellow);
//textFragment.TextState.Underline = true;
}
}
// Save resulting PDF document.
pdfDocument.Save(dataDir + “sampleoutput2.pdf”);
// Let user know about the outcome of the processing.
System.Console.WriteLine(“Text replaced successfully!”);
}