Hi Aspose Team,
Using below source code we are creating hyperlink on attached PDF file (TransferDocument.pdf).
We are trying to create hyperlink on “Deeds, Leases; official Records and Contracts on page 219” text in the attached PDF file. The below code is considering from “Deeds, Leases; official Records and Contract” is one segment and remaining text “s on page 219” are another segment. Hence, this case 2 link annotation is created for single line text. Refer the Attached image file for more details.
Please let me know how to create single link annotation for entire text (“Deeds, Leases; official Records and Contracts on page 219”) using Aspose in this case.
NOTE: it’s very high priority task for me. Please let know your feedback ASAP.
foreach (Aspose.Pdf.Page pdfPage in PDFDocument.Pages)
{
//create TextAbsorber object to find all the phrases matching the regular expression
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("<>", new TextSearchOptions(true));
pdfPage.Accept(textFragmentAbsorber);
//get the extracted text fragments
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
if (textFragmentCollection.Count > 0)
{
foreach (TextFragment textFragment in textFragmentCollection)
{
// Use the text segments when the text fragment has a newline char.
if (textFragment.Text.Contains(Environment.NewLine))
{
foreach (TextSegment s in textFragment.Segments)
{
s.TextState.ForegroundColor = Aspose.Pdf.Color.Blue;
// Create the annotation for each segment.
LinkAnnotation link = new LinkAnnotation(pdfPage, rect);
Aspose.Pdf.Point start = new Aspose.Pdf.Point(rect.LLX, rect.LLY);
Aspose.Pdf.Point end = new Aspose.Pdf.Point(rect.LLX + rect.Width, rect.LLY);
LineAnnotation line = new LineAnnotation(pdfPage, rect, start, end);
line.Color = Aspose.Pdf.Color.Blue;
line.Border = new Border(link) { Width = 1 };
link.Border = new Border(link) { Width = 0 };
link.Action = new GoToURIAction(url);
pdfPage.Annotations.Add(link);
pdfPage.Annotations.Add(line);
}
}
else // Use the whole text fragment.
{
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Blue;
LinkAnnotation link = new LinkAnnotation(pdfPage, rect);
Aspose.Pdf.Point start = new Aspose.Pdf.Point(rect.LLX, rect.LLY);
Aspose.Pdf.Point end = new Aspose.Pdf.Point(rect.LLX + rect.Width, rect.LLY);
LineAnnotation line = new LineAnnotation(pdfPage, rect, start, end);
line.Color = Aspose.Pdf.Color.Blue;
line.Border = new Border(link) { Width = 1 };
link.Border = new Border(link) { Width = 0 };
link.Action = new GoToURIAction(url);
pdfPage.Annotations.Add(link);
pdfPage.Annotations.Add(line);
}
}
}
}
Regards,
Ganesan. B