Rank: Newbie
Groups: Registered
Joined: 1/4/2017(UTC) Posts: 1  Location: Cape Town
|
Hi Devs,
I would like to implement annotations using this great library. However, I am experiencing problems getting the co-ordinates of the selected text to be used for highlights, bookmarks etc.
I have read the docs and have gone through the FAQ. Will you please show me an example of how I can get these points.
Thanks,
GeeMaster
|
|
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,138
Thanks: 10 times Was thanked: 133 time(s) in 130 post(s)
|
Code:
var selInfo = pdfViewer1.SelectInfo;
var pages = pdfViewer1.Document.Pages;
for (int i = selInfo.StartPage; i <= selInfo.EndPage; i++)
{
var rects = GetSelectedTextRects(pages[i], i, selInfo);
}
private List<Rectangle> GetSelectedTextRects(PdfPage page, int pageIndex, SelectInfo selInfo)
{
var ret = new List<Rectangle>();
if (selInfo.StartPage < 0)
return ret;
if (pageIndex >= selInfo.StartPage && pageIndex <= selInfo.EndPage)
{
int s = 0;
if (pageIndex == selInfo.StartPage)
s = selInfo.StartIndex;
int len = page.Text.CountChars;
if (pageIndex == selInfo.EndPage)
len = (selInfo.EndIndex + 1) - s;
var ti = page.Text.GetTextInfo(s, len);
foreach (var rc in ti.Rects)
{
var pt1 = pdfViewer1.PageToClient(pageIndex, new PointF(rc.left, rc.top));
var pt2 = pdfViewer1.PageToClient(pageIndex, new PointF(rc.right, rc.bottom));
int x = pt1.X < pt2.X ? pt1.X : pt2.X;
int y = pt1.Y < pt2.Y ? pt1.Y : pt2.Y;
int w = pt1.X > pt2.X ? pt1.X - pt2.X : pt2.X - pt1.X;
int h = pt1.Y > pt2.Y ? pt1.Y - pt2.Y : pt2.Y - pt1.Y;
ret.Add(new Rectangle(x, y, w, h));
}
}
return ret;
}
|
|
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The Patagames Software Support Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close