RX-1
RX-2
RX-3
RX-10
RX-11
RX-20
RX-22 (and the list goes on)
When using the code below, the links work, but I am getting double links for RX-11, RX-20, and RX-22, etc. (e.g. RX-11 has a link for RX-1 underneath a link for RX-11 - see image below)
- Code: Select all
PdfDocument sourcePDF = new PdfDocument();
sourcePDF.LoadFromFile(documentPath);
PdfTextFind[] result = null;
foreach (var exhibit in exhibitInfo)
{
var searchString = exhibit.ExhibitName;
var linkPath = exhibit.ExhibitPath;
//Check each page individually
foreach (PdfPageBase page in sourcePDF.Pages)
{
result = page.FindText(searchString).Finds;
foreach(PdfTextFind find in result)
{
PdfLaunchAction launchAction = new PdfLaunchAction(linkPath, PdfFilePathType.Relative);
RectangleF rect = new RectangleF(find.Position.X, find.Position.Y, find.Size.Width, find.Size.Height);
PdfActionAnnotation annotation = new PdfActionAnnotation(rect, launchAction);
annotation.Border = new PdfAnnotationBorder(2);
annotation.Color = new Spire.Pdf.Graphics.PdfRGBColor(System.Drawing.Color.Blue);
(page as PdfPageWidget).AnnotationsWidget.Add(annotation);
}
result = null;
}
}
For completeness, exhibit.ExhibitName and exhibit.ExhibitPath are from a List<ExhibitInfo> where ExhibitInfo is:
- Code: Select all
namespace HyperLinker
{
public class ExhibitInfo
{
public string ExhibitName;
public string ExhibitPath;
public ExhibitInfo()
{
}
}
}
Now, in the first code block, I have tried replacing
- result = page.FindText(searchString).Finds;
with
- result = page.FindText(searchString, true).Finds;
I get the same result, double boxes on the matching entries (RX-10, oddly, does not) as you can see from the image below:
I have also tried "result = page.FindText(searchString, true, false).Finds;" which results in no links being placed.
"result = page.FindText(searchString, false, false).Finds;" is not much help either, as the result is the same as leaving out the bool values all together.
If it is any help:
Spire.Pdf 5.8.16.2040
runtime version v4.0.30319