var Count, LI: Integer; Result1, Result2: TStringList; LineAnnot: TgtPDFLineAnnotation; URI: TgtPDFURIAction; GoToRAct: TgtPDFGoToRAction; LinkAnnot1, LinkAnnot2 : TgtPDFLinkAnnotation; begin PDFDoc.MeasurementUnit := muPixels; // Create the string lists Result1 := TStringList.Create; Result2 := TStringList.Create; // Load the input document into the PDFDoc component PDFDoc.LoadFromFile('Input.pdf'); // Create instance of TgtPDFLineAnnotation and assign the properties LineAnnot := TgtPDFLineAnnotation.Create; LineAnnot.LineBeginingStyle := laNone; LineAnnot.LineEndingStyle := laNone; // Search all the instances of Text1 in the document and add them to the string list Count := PDFDoc.SearchAll(Text1, [stWholeWord], Result1); // If the Text1 is present in the document, add the link annotation with URI action if Count > 0 then begin // Create instance of TgtPDFLinkAnnotation and assign the properties LinkAnnot1 := TgtPDFLinkAnnotation.Create; URI := TgtPDFURIAction.Create ; URI.URI := edLink.Text; LinkAnnot1.Action := URI; LineAnnot.LineInteriorColor := clBlue; // Add the link and line annotation to all the instances of Text1 in the document for LI := 0 to Count - 1 do begin LinkAnnot1.RectLeft := TgtPDFTextElement(Result1.Objects[LI]).XCordOrigin; LinkAnnot1.RectTop := TgtPDFTextElement(Result1.Objects[LI]).YCordOrigin; LinkAnnot1.RectRight := LinkAnnot1.RectLeft + PDFDoc.GetCharWidth (Trim(edText1.Text), TgtPDFTextElement(Result1.Objects[LI]).Font); LinkAnnot1.RectBottom := LinkAnnot1.RectTop - TgtPDFTextElement(Result1. Objects[LI]).Font.Height; LineAnnot.gtLine(LinkAnnot1.RectLeft, LinkAnnot1.RectBottom+2, LinkAnnot1.RectRight, LinkAnnot1.RectBottom+2); PDFDoc.InsertAnnotation(LinkAnnot1, TgtPDFTextElement(Result1. Objects[LI]).PageNumber); PDFDoc.InsertAnnotation(LineAnnot, TgtPDFTextElement(Result1. Objects[LI]).PageNumber); end; end; // Search all the instances of Text2 in the document and add them to the string list Count := PDFDoc.SearchAll(Text2, [stWholeWord], Result2); // If the Text1 is present in the document, add the link annotation with GoToRAct action if Count > 0 then begin // Create instance of TgtPDFLinkAnnotation and assign the properties LinkAnnot2 := TgtPDFLinkAnnotation.Create; GoToRAct := TgtPDFGoToRAction.Create; GoToRAct.FileName := edFileName.Text; GoToRAct.OpenInNewWindow := True; GoToRAct.DestinationType := dtFitH ; GoToRAct.PageNo := 2; LinkAnnot2.Action := GoToRAct; LineAnnot.LineInteriorColor := clRed; // Add the link and line annotation to all the instances of Text2 in the document for LI := 0 to Count - 1 do begin LinkAnnot2.RectLeft := TgtPDFTextElement(Result2.Objects[LI]).XCordOrigin; LinkAnnot2.RectTop := TgtPDFTextElement(Result2.Objects[LI]).YCordOrigin ; LinkAnnot2.RectRight := LinkAnnot2.RectLeft + PDFDoc.GetCharWidth (Trim(edText2.Text), TgtPDFTextElement(Result2.Objects[LI]).Font); LinkAnnot2.RectBottom := LinkAnnot2.RectTop - TgtPDFTextElement(Result2. Objects[LI]).Font.Height; LineAnnot.gtLine(LinkAnnot2.RectLeft, LinkAnnot2.RectBottom+2, LinkAnnot2.RectRight, LinkAnnot2.RectBottom+2); PDFDoc.InsertAnnotation(LinkAnnot2, TgtPDFTextElement(Result2. Objects[LI]).PageNumber); PDFDoc.InsertAnnotation(LineAnnot, TgtPDFTextElement(Result1. Objects[LI]).PageNumber); end; end; // Free the string lists for LI := 0 to Count - 1 do Result1.Objects[LI].Free; Result1.Free; for LI := 0 to Count - 1 do Result2.Objects[LI].Free; Result2.Free; // Save the changes made to the document PDFDoc.SaveToFile('Output.pdf'); end;