Hi,
is possible get encircled text contained under annotation rectangle?
please a small example in delphi
Thank you Miro
get encircled text contained under annotation rectangle ?
Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange
-
- User
- Posts: 59
- Joined: Sat May 09, 2009 3:05 pm
-
- User
- Posts: 664
- Joined: Tue Nov 14, 2006 12:23 pm
Re: get encircled text contained under annotation rectangle ?
Hello Miro,
I'm afraid that we don't have any samples of such kind.
However this can be done by using JS to get annotation coordinates and then get coordinates of text in PDF and try to find any intersections in this coordinates.
Best regards
I'm afraid that we don't have any samples of such kind.
However this can be done by using JS to get annotation coordinates and then get coordinates of text in PDF and try to find any intersections in this coordinates.
Best regards
-
- User
- Posts: 61
- Joined: Tue Jun 12, 2007 9:21 pm
Re: get encircled text contained under annotation rectangle ?
You might look at the "problems getting chars Quad in .NET" as one of the messages has some code that I use to do what I think your asking.
-
- User
- Posts: 59
- Joined: Sat May 09, 2009 3:05 pm
Re: get encircled text contained under annotation rectangle ?
Yes! thank you very much
Miro
Miro
-
- Site Admin
- Posts: 19913
- Joined: Mon Jan 12, 2009 8:07 am
Re: get encircled text contained under annotation rectangle ?
tdonovan,
Thanks for the help.
And miromr, please let us know if this helped you solve your problem.
Best,
Stefan
Thanks for the help.
And miromr, please let us know if this helped you solve your problem.
Best,
Stefan
-
- User
- Posts: 59
- Joined: Sat May 09, 2009 3:05 pm
Re: get encircled text contained under annotation rectangle ?
Hi,
Is not it perfect but sufficient for my needs
Miromr
Var
scr: WideString;
result: WideString;
S,Str: String;
SL: TStringList;
DataIn,DataOut:OleVariant;
Words,Word: IPDFXCsmartp;
i,WordCount: Integer;
SelRect: TMyRect;
WordRect: TMyRect;
vArr:array of OLEVariant;
Y: Double;
begin
Memo1.Lines.Clear;
Scr := 'var OutStr = ""; var Annot = this.getAnnot(0, "mySquare");'
+'Result = Annot.rect;';
try
PDFview.RunJavaScript (scr,result,0,0);
except
on ex : EOleException do
ShowErrorMessage(ex.ErrorCode);
end;
SL:= TStringList.Create;
SL.Delimiter :=',';
SL.DelimitedText:=Result;
for I := 0 to SL.Count - 1 do
Begin
SL:=StringReplace(SL, '.', DecimalSeparator,[]);
End;
SelRect.xlb:=StrToFloat(SL[0]);
SelRect.ylb:=StrToFloat(SL[1]);
SelRect.xrt:=StrToFloat(SL[2]);
SelRect.yrt:=StrToFloat(SL[3]);
SL.Free;
PDFView.DoVerb('Documents[0].Pages[0].Text.Words', '.SP', DataIn, DataOut, 0);
Words:=IDispatch(DataOut) as IPDFXCsmartp;
Words.GetProperty('Count', DataOut, 0);
WordCount:=DataOut;
SetLength(vArr,8);
Y:=0;
S:='';
for I := 1 to WordCount do
Begin
Words.GetItemPointByIndex(i, Word);
if (Word = nil) then
Continue;
Word.GetProperty('String', DataOut, 0);
Str:=dataOut;
if Str='' then Continue;
Word.GetProperty('Quads.Value', DataOut, 0);
vArr:=DataOut;
WordRect.xlb:=vArr[0];
WordRect.ylb:=vArr[1];
WordRect.xrt:=vArr[4];
WordRect.yrt:=vArr[5];
if RectIntersect(WordRect,SelRect) then
Begin
if Y=0 then
Y:=WordRect.ylb;
If Y=WordRect.ylb Then
Begin
if S='' then
S:=Str
else
S:=S+' '+Str;
End
else
Begin
Memo1.Lines.Add(S);
S:=Str;
Y:=WordRect.ylb;
End;
End;
End;
if S<>'' then
Begin
Memo1.Lines.Add(S);
S:=Str;
Y:=0;
End;
end;
Is not it perfect but sufficient for my needs
Miromr
Var
scr: WideString;
result: WideString;
S,Str: String;
SL: TStringList;
DataIn,DataOut:OleVariant;
Words,Word: IPDFXCsmartp;
i,WordCount: Integer;
SelRect: TMyRect;
WordRect: TMyRect;
vArr:array of OLEVariant;
Y: Double;
begin
Memo1.Lines.Clear;
Scr := 'var OutStr = ""; var Annot = this.getAnnot(0, "mySquare");'
+'Result = Annot.rect;';
try
PDFview.RunJavaScript (scr,result,0,0);
except
on ex : EOleException do
ShowErrorMessage(ex.ErrorCode);
end;
SL:= TStringList.Create;
SL.Delimiter :=',';
SL.DelimitedText:=Result;
for I := 0 to SL.Count - 1 do
Begin
SL:=StringReplace(SL, '.', DecimalSeparator,[]);
End;
SelRect.xlb:=StrToFloat(SL[0]);
SelRect.ylb:=StrToFloat(SL[1]);
SelRect.xrt:=StrToFloat(SL[2]);
SelRect.yrt:=StrToFloat(SL[3]);
SL.Free;
PDFView.DoVerb('Documents[0].Pages[0].Text.Words', '.SP', DataIn, DataOut, 0);
Words:=IDispatch(DataOut) as IPDFXCsmartp;
Words.GetProperty('Count', DataOut, 0);
WordCount:=DataOut;
SetLength(vArr,8);
Y:=0;
S:='';
for I := 1 to WordCount do
Begin
Words.GetItemPointByIndex(i, Word);
if (Word = nil) then
Continue;
Word.GetProperty('String', DataOut, 0);
Str:=dataOut;
if Str='' then Continue;
Word.GetProperty('Quads.Value', DataOut, 0);
vArr:=DataOut;
WordRect.xlb:=vArr[0];
WordRect.ylb:=vArr[1];
WordRect.xrt:=vArr[4];
WordRect.yrt:=vArr[5];
if RectIntersect(WordRect,SelRect) then
Begin
if Y=0 then
Y:=WordRect.ylb;
If Y=WordRect.ylb Then
Begin
if S='' then
S:=Str
else
S:=S+' '+Str;
End
else
Begin
Memo1.Lines.Add(S);
S:=Str;
Y:=WordRect.ylb;
End;
End;
End;
if S<>'' then
Begin
Memo1.Lines.Add(S);
S:=Str;
Y:=0;
End;
end;
-
- Site Admin
- Posts: 19913
- Joined: Mon Jan 12, 2009 8:07 am
Re: get encircled text contained under annotation rectangle ?
Glad the problem is solved 
Best,
Stefan

Best,
Stefan