ImageEn, unit iexUserInteractions

TIEPdfViewer.ScrToPage

TIEPdfViewer.ScrToPage


Declaration

function ScrToPage(ScrX, ScrY: Integer; CheckBounds: Boolean = True): TDPoint; overload;
function ScrToPage(ScrRect: TRect; CheckBounds: Boolean = True): TDRect; overload;


Description

Convert a screen position (in pixels) to a value on the current page (in points).
When CheckBounds is true, the result will be -1 for values that are outside the page area

Note:
 PDF Points are not affected by the display DPI
 The origin of PDF page points (i.e. 0,0) is the bottom-left


Examples

// Convert a screen point to a page point
pagePt := ImageEnView1.PdfViewer.ScrToPage( 100, 100 );


// Show position on page as the cursor is moved
procedure TfrmMain.ImageEnView1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
  pt: TDPoint;
begin
  pt := ImageEnView1.PdfViewer.ScrToPage( X, Y, True );
  if ( pt.X = -1 ) or ( pt.Y = -1 ) then
    Caption := 'Page Pos: INVALID'
  else
    Caption := format( 'Page Pos: %d, %d', [ Round( pt.X ), Round( pt.Y )]);
end;


// Delete the item clicked on
procedure TfrmMain.ImageEnView1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  idx: Integer;
  pt: TDPoint;
begin
  pt := ImageEnView1.PdfViewer.ScrToPage( X, Y, True );
  idx := ImageEnView1.PdfViewer.Objects.FindObjectAt( pt );
  if idx > -1 then
    if MessageDlg( format( 'Delete object %d?', [ idx + 1 ]), mtConfirmation, [ mbYes,mbNo ], 0 ) = mrYes then
    begin
      ImageEnView1.PdfViewer.Objects.RemoveObject( idx );
      ImageEnView1.Invalidate();
    end;
end;


See Also

 PageToScr