Hi Team,
I have tried with Aspose.pdf.dll version 10.4.0.0 and its also not working as expected.
Please refer the below my source code:
using Aspose.Pdf;
using Aspose.Pdf.InteractiveFeatures;
using Aspose.Pdf.InteractiveFeatures.Annotations;
using Aspose.Pdf.Text;
using Aspose.Pdf.Text.TextOptions;
using System.IO;
using System.Diagnostics;
string spattern = @“(?im)\b2015\b”;
string inPutFile = @“D:\Projects\EaglePro_CMMI\PoC\TestHyperlink\TestHyperlink\Files\Input\705967-bad.pdf”;
string outPutFile = @“D:\Projects\EaglePro_CMMI\PoC\TestHyperlink\TestHyperlink\Files\Output\Output.pdf”;
TextFragmentCollection textFragmentCollection;
Stream input = System.IO.File.OpenRead(inPutFile);
Document doc = new Document(input);
TextFragmentAbsorber textFragmentAbsorber;
//IList annotations;
MemoryStream output = new MemoryStream();
// Create links for each dictionary entry.
foreach (Page p in doc.Pages)
{
//create TextAbsorber object to find all instances of the input search phrase
textFragmentAbsorber = new TextFragmentAbsorber(spattern, new TextSearchOptions(true));
//accept the absorber for all the pages
p.Accept(textFragmentAbsorber);
//Get the extracted text fragments
textFragmentCollection = textFragmentAbsorber.TextFragments;
//Loop through the fragments and create links.
foreach (TextFragment textFragment in textFragmentCollection)
{
// If the found text fragment contains newline character, reduce the box to the end of the of the line.
foreach (TextSegment s in textFragment.Segments)
{
LinkAnnotation link = new LinkAnnotation(p, s.Rectangle);
Aspose.Pdf.Point start = new Aspose.Pdf.Point(s.Rectangle.LLX, s.Rectangle.LLY);
Aspose.Pdf.Point end = new Aspose.Pdf.Point(s.Rectangle.LLX + s.Rectangle.Width, s.Rectangle.LLY);
LineAnnotation line = new LineAnnotation(p, s.Rectangle, start, end);
s.TextState.ForegroundColor = Aspose.Pdf.Color.Blue;
line.Color = Aspose.Pdf.Color.Blue;
s.TextState.Underline = true;
link.Contents = s.Text;
line.Border = new Aspose.Pdf.InteractiveFeatures.Annotations.Border(link) { Width = 1 };
link.Border = new Aspose.Pdf.InteractiveFeatures.Annotations.Border(link) { Width = 0 };
p.Annotations.Add(link);
p.Annotations.Add(line);
}
}
}
// Save the document to memory stream.
doc.Save(output);
byte[] bytes;
bytes = new byte[output.Length];
output.Read(bytes, 0, (int)output.Length);
fs.Write(bytes, 0, bytes.Length);
output.Close();
ProcessStartInfo psi = new ProcessStartInfo(outPutFile);
psi.UseShellExecute = true;
Process.Start(psi);
Regards,
Ganesan. B