Web SDKv1.0.0

PDFViewer.clientToPage()

The reverse of pageToClient: CSS pixels from the container's top-left corner, as the page holds them.
methodCoordinatessince 1.0.0

Signature

clientToPage<T extends Rect | Point>(value: T, pageIndex: number): T | null

Parameters

ParameterTypeDescription
valueRect | PointCSS pixels from the container's top-left corner.
pageIndexnumberZero-based page index.

Returns

Rect | Point | null null before the page is laid out, or on a destroyed viewer.

Throws

  • INVALID_ARGUMENT for a page index the document has not, or a value that is neither a Point nor a Rect of finite numbers.

Example

TypeScript
container.addEventListener('click', (e) => {
  const bounds = container.getBoundingClientRect();
  const at = viewer.clientToPage({ x: e.clientX - bounds.left, y: e.clientY - bounds.top }, 0);
  // at: where on page 0 the user clicked, in page space, or null
});

More in PDFViewer