Find X,Y Position

<< Click to Display Table of Contents >>

Navigation:  Commands >

Find X,Y Position

 

COMPDF_ScreenToClient expects the X coordinate in hi word, the Y coordinate in low word.

The result is the page page. The PDF X and Y coordinate can be read with COMPDF_GetScreenToClientX and COMPDF_GetScreenToClientY

 

The function ScreenToPage can be used to calculate the point on a certain PDF page which corresponds to a certain point on screen.

 

It is implemented like this:

 

procedure TWPViewPDF.ScreenToPage( X, Y : Integer; Var pdf_x, pdf_y, pdf_page : Integer );

begin

 pdf_page := Command(COMPDF_ScreenToClient, X shl 16 or Y);

 pdf_x := Command(COMPDF_GetScreenToClientX);

 pdf_y := Command(COMPDF_GetScreenToClientY);

end;

 

Command COMPDF_ClientToScreenPage sets the page number (0 based) for the next call to COMPDF_ClientToScreenXY. It returns -1 if the page number is not valid.

COMPDF_ClientToScreenXY expects the PDF page X coordinate (in 72 dpi!) in hi word, the Y coordinate in low word.

The Result is the screen coordinate X in high word, the y coordinate in lo word.

 

The VCL also implements:

 

function TWPViewPDF.PageToScreen( pdf_x, pdf_y, pdf_page : Integer; var X, Y : Integer ) : Boolean;

var i : Integer;

begin

 Result := Command(COMPDF_ClientToScreenPage, pdf_page)>=0;

 if Result then

 begin

   i := Command(COMPDF_ClientToScreenXY, pdf_x shl 16 or pdf_y);

   x := (i shr 16) and $FFFF;

   y := i and $FFFF;

 end else

 begin

   x := 0;

   y := 0;

 end;

end;