public interface

ViewProjection

com.pspdfkit.projection.ViewProjection

Class Overview

Projection between the view coordinate space and the PDF coordinate space. To retrieve an instance of this, use getViewProjection(). For more information on coordinate spaces and coordinate conversions, please refer to our Coordinate Space Conversion online guide.

Summary

Public Methods
abstract Matrix getPageToViewTransformation(int pageIndex, Matrix reuse)
Returns a Matrix for transforming PDF coordinates to view coordinates.
abstract Matrix getViewToPageTransformation(int pageIndex, Matrix reuse)
Returns a Matrix for transforming view coordinates to PDF coordinates.
abstract void toPdfPoint(PointF point, int pageIndex)
Converts the coordinates stored within point from the view coordinate space (i.e.
abstract void toPdfRect(RectF rect, int pageIndex)
Converts the view coordinates stored in rect to PDF coordinates on the given pageIndex.
abstract void toViewPoint(PointF point, int pageIndex)
Converts the coordinates stored within point from the PDF coordinate space of the given pageIndex to the view coordinate space (i.e.
abstract void toViewRect(RectF rect, int pageIndex)
Converts the PDF coordinates stored in rect (of the given pageIndex) to view coordinates.

Public Methods

public abstract Matrix getPageToViewTransformation (int pageIndex, Matrix reuse)

Returns a Matrix for transforming PDF coordinates to view coordinates. The matrix can be used to map coordinates on the PDF page at pageIndex to view coordinates on the fragment. Note that this method may throw IllegalStateException if no document has been loaded yet, or if the requested page is not yet part of the fragment's view hierarchy.

Parameters
pageIndex Number of the page for which to retrieve the transformation (starting at 0).
reuse A matrix object to reuse for calculation. May be null if a new matrix should be created.
Returns
  • Transformation matrix for converting page coordinates to view coordinates.
Throws
IllegalStateException if there is no transformation for the given page (e.g. the document is not yet loaded, or the specified page doesn't exist).

public abstract Matrix getViewToPageTransformation (int pageIndex, Matrix reuse)

Returns a Matrix for transforming view coordinates to PDF coordinates. The matrix can be used to map view coordinates on the fragment to coordinates on the PDF page at pageIndex. Note that this method may throw IllegalStateException if no document has been loaded yet, or if the requested page is not yet part of the fragment's view hierarchy.

Parameters
pageIndex Number of the page for which to retrieve the transformation (starting at 0).
reuse A matrix object to reuse for calculation. May be null if a new matrix should be created.
Returns
  • Transformation matrix for converting page coordinates to view coordinates.
Throws
IllegalStateException if there is no transformation for the given page (e.g. the document is not yet loaded, or the specified page doesn't exist).

public abstract void toPdfPoint (PointF point, int pageIndex)

Converts the coordinates stored within point from the view coordinate space (i.e. screen pixels) to PDF coordinate space of the given pageIndex. This method modifies point in place.

This method throws an exception if called before the document has been laid out, or if a conversion for the given pageIndex is not possible (e.g. requested page number is invalid). See onDocumentLoaded(PdfDocument) which is called after the document has been loaded, and the document view has been laid out.

Parameters
point Point containing view coordinates (pixels) that should be converted to PDF coordinates.
pageIndex Target page for the conversion (0 denotes the first page).

public abstract void toPdfRect (RectF rect, int pageIndex)

Converts the view coordinates stored in rect to PDF coordinates on the given pageIndex. This method modifies rect in place.

This method throws an exception if called before the document has been laid out, or if a conversion for the given pageIndex is not possible (e.g. requested page number is invalid). See onDocumentLoaded(PdfDocument) which is called after the document has been loaded, and the document view has been laid out.

Parameters
rect View coordinates.
pageIndex Target page for the conversion (0 denotes the first page).

public abstract void toViewPoint (PointF point, int pageIndex)

Converts the coordinates stored within point from the PDF coordinate space of the given pageIndex to the view coordinate space (i.e. screen pixels). This method modifies point in place.

This method throws an exception if called before the document has been laid out, or if a conversion for the given pageIndex is not possible (e.g. requested page number is invalid). See onDocumentLoaded(PdfDocument) which is called after the document has been loaded, and the document view has been laid out.

Parameters
point PDF coordinates on the given pageIndex that should be converted to coordinates of the document view (pixels).
pageIndex Target page for the conversion (0 denotes the first page).

public abstract void toViewRect (RectF rect, int pageIndex)

Converts the PDF coordinates stored in rect (of the given pageIndex) to view coordinates. This method modifies rect in place.

This method throws an exception if called before the document has been laid out, or if a conversion for the given pageIndex is not possible (e.g. requested page number is invalid). See onDocumentLoaded(PdfDocument) which is called after the document has been loaded, and the document view has been laid out.

Parameters
rect PDF coordinates.
pageIndex Target page of the coordinates (0 denotes the first page).