[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with Search Results of PDFDocument-Class


Am 01.09.24 um 06:35 schrieb BB:
guess we need to determine a range based on the topmost-leftmost character and the bottommost-rightmost character position (as the last line may not be as wide) for both realms and work out a conversion from there.

The following solution seems to do what we need and also worked perfectly with a complex PDF document. It even marked words correctly which were part of the footer and turned by 90 degrees:

Public Sub DocumentView1_Draw(Page As Integer, Width As Integer, Height As Integer)
    Dim hOverlayImage As Image
    Dim aRectF As RectF[]
    Dim i As Integer
    Dim xFactor As Float  <----- new
    Dim yFactor As Float  <----- new

    'Draw the overlay of search results if any
    If cSearchResult.Exist(Page) Then
       xFactor = Width / hDoc[Page].W     <------ new
       yFactor = Height / hDoc[Page].H    <------ new
       aRectF = cSearchResult[Page]
       hOverlayImage = New Image(width, Height)
       Paint.Begin(hOverlayImage)
         Paint.Brush = Paint.Color(Color.SetAlpha(Color.red, 180))
         For i = 0 To aRectF.Max
           'Paint.Rectangle(aRectF[i].x, aRectF[i].y, aRectF[i].w, aRectF[i].h) 'old            Paint.Rectangle(aRectF[i].x * xFactor, Height - aRectF[i].h * yFactor - aRectF[i].y * yFactor, aRectF[i].w * xFactor, aRectF[i].h * yfactor) '<---- new
           Paint.Fill
         Next
       Paint.End
    End If

    .....

This is what it does (point 4. was guess work):

1. The different co-ordinate realms of the DocumentViewer and the PDFDocument are used to calculate translation factors,

2. the coordinates and dimensions of the hit rectangles are corrected by the factors,

3. the target coordinates are used upside down,

4. and the target coordinates are shifted by the height of the corrected hit rectangle.

I regard the subject as solved.

Regards

Claus





References:
Re: Problem with Search Results of PDFDocument-ClassBB <adamnt42@xxxxxxxxx>