Developer Tools
|
Office Productivity Applications
|
Enterprise Solutions
|
|||||||||||||||||||||||||||
PDFtoolkit allows you to find occurrences of a word or phrase in any page of a PDF document with its search routines SearchFirst and SearchNext.
A link annotation could be inserted in these occurrences to a destination somewhere else in the document using the InsertAnnotation method with any of the following actions:
By adding a link annotation to the occurrence of a particular word or phrase using PDFtoolkit, you can make that word or phrase an active link in the PDF file that users can interact with.
Here are the steps to add link annotations to all occurences of a given search text in a PDF file:
...
gtPDFDocument.Loadfromfile('Input.pdf');
...
...
SearchResult := TStringList.Create;
Count := gtPDFDocument.SearchAll(
Text,
[stWholeWord],
SearchResult
);
...
...
LineAnnot := TgtPDFLineAnnotation.Create;
LineAnnot.LineBeginingStyle := laNone;
LineAnnot.LineEndingStyle := laNone;
LinkAnnot := TgtPDFLinkAnnotation.Create;
URI := TgtPDFURIAction.Create ;
URI.URI := edLink.Text;
LinkAnnot.Action := URI;
for LI := 0 to Count - 1 do
begin
LinkAnnot.RectLeft := TgtPDFTextElement(SearchResult.
Objects[LI]).XCordOrigin;
LinkAnnot.RectTop := TgtPDFTextElement(
SearchResult.Objects[LI]).YCordOrigin;
LinkAnnot.RectRight := LinkAnnot.RectLeft
+ PDFDoc.GetCharWidth(Trim('Text'),
TgtPDFTextElement(SearchResult.Objects[LI]).Font);
LinkAnnot.RectBottom := LinkAnnot.RectTop -
TgtPDFTextElement(SearchResult.Objects[LI]).
Font.Height;
LineAnnot.gtLine(LinkAnnot.RectLeft,
LinkAnnot.RectBottom + 2, LinkAnnot.RectRight,
LinkAnnot.RectBottom + 2);
gtPDFDocument.InsertAnnotation(
LinkAnnot, TgtPDFTextElement(
SearchResult.Objects[LI]).PageNumber);
gtPDFDocument.InsertAnnotation(LineAnnot,
TgtPDFTextElement(SearchResult.Objects[LI]).
PageNumber);
end;
...
...
gtPDFDocument.SaveToFile('Output.pdf');
...
This PDF file contains link annotation with URI action. When the mouse pointer moves over the search text ("Pascal"), the link annotation will be displayed. Clicking the annotation opens the link in a browser.
Downloads:
| Privacy | Legal | Feedback | Newsletter | © 2002-2010 Gnostice Information Technologies Private Limited. All rights reserved. |
This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows users are advised to use Microsoft ClearType Tuning for optimal experience. Linux and other users can enable font smoothing, as supported by their OS. Also, please use the latest version of a standards-compliant browser such as Opera, FireFox, Chrome or Safari.