API referenceRendering & Viewer

rasClientToPage

Two independent device-pixel → PDF-user-space coordinate

C
BOOL32 __stdcall rasClientToPage(IPGC CachePtr, int32_t X, int32_t Y, int32_t* PageNum, double* PX, double* PY);
int32_t __stdcall rasPixToPDF(IPGC CachePtr, int32_t X, int32_t Y, double* OutX, double* OutY);
Delphi
function rasClientToPage(CachePtr: IPGC; X, Y: Integer; var PageNum: Integer; var PX, PY: Double): LongBool; stdcall;
function rasPixToPDF(CachePtr: IPGC; X, Y: Integer; var OutX, OutY: Double): Integer; stdcall;

Purpose. Two independent device-pixel → PDF-user-space coordinate mappers, with genuinely different scope.

Description. rasClientToPage is the fuller, hit-testing mapper: it walks every page in the document (1..PageCount), using the *display* (rotated) pixel size (VwPageSizePx) and the page's actual top offset in the scrolled column (VwPageTop) to find which page contains (X, Y), horizontally centers each page within the viewport ((C.Width - wpx) div 2, clamped to at least HBorder), and — genuinely honoring the cache's rotation — inverts the same rotation mapping the paint path applies (RotateRGB's forward mapping, Page Navigation, Layout, and Geometry/E07) to convert the hit device pixel back into *unrotated* page-local pixels before dividing by zoom and flipping Y to PDF's bottom-up origin. rasPixToPDF is far simpler and does not hit-test at all: it always operates on C.CurrPage (no page search), ignores rotation entirely, and does a plain X/z, ph - Y/z conversion — it will produce a wrong result for any point outside the current page's own displayed rectangle, and an un-rotated result if the cache has a non-zero rasSetRotate value.

Parameters.

ParameterDescription
CachePtrTarget page cache.
X, YDevice pixel coordinates (viewport-relative).
PageNum*(ClientToPage only)* Output: which page was hit (searches all pages).
PX, PY / OutX, OutYOutput: PDF user-space coordinates (bottom-left origin).

Return value. rasClientToPage: True if (X, Y) falls within some page's displayed rectangle. rasPixToPDF: the current page number on success (always C.CurrPage, regardless of where (X,Y) actually falls); 0 if CachePtr/document/page size doesn't resolve.

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
[return: MarshalAs(UnmanagedType.Bool)]
Area
Rendering & Viewer
Category

Rasterizer/Rendering

Exported names

rasClientToPage

String variants

The …A form takes UTF-8, …W takes UTF-16; a bare name aliases the ANSI form.

See working code

Worked examples — complete programs in ten languages.