PDFiumVCL Docs

DeviceToPage method

Component: TPdf  ·  Unit: PDFium
Convert the screen coordinate of a point to page coordinate.

Syntax

function DeviceToPage(X, Y, Left, Top, Width, Height: Integer; Rotation: TRotation; out PageX, PageY: Double): Boolean;

X, YInteger. The device-space coordinates of the point to convert (screen pixels, origin at top-left).
Left, Top, Width, HeightInteger. The rendering rectangle that was passed to the corresponding RenderPage call.
RotationTRotation. The page rotation used when rendering. Must match the value passed to RenderPage.
PageX, PageYDouble. Output parameters that receive the converted PDF user-space coordinates (origin at lower-left, units in points).

Return Value

Returns True if the conversion succeeded, or False if it failed (for example, if no page is loaded).

Description

Converts a point from device space (screen pixels) to PDF user space (points). Use this method to translate a mouse click position on a rendered page back to the corresponding position on the PDF page.

PDF user space has its origin at the lower-left corner of the page, with the Y axis pointing upward. Device space has its origin at the top-left corner of the render rectangle, with the Y axis pointing downward.

The Left, Top, Width, Height, and Rotation parameters must match exactly what was passed to the RenderPage call that produced the image being clicked on.

Example

// Translate a mouse click on the painted page to PDF coordinates
procedure TForm1.PdfPanelMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  PageX, PageY: Double;
begin
  if Pdf.DeviceToPage(X, Y, 0, 0, PdfPanel.Width, PdfPanel.Height,
    ro0, PageX, PageY) then
    StatusBar1.SimpleText := Format('Page pos: %.1f, %.1f pt', [PageX, PageY]);
end;

See Also

PageToDevice, RenderPage, PageWidth, PageHeight