java.lang.Object
   ↳ android.support.v4.app.Fragment
     ↳ com.pspdfkit.ui.PdfFragment
Known Direct Subclasses

Class Overview

Fragment that actually displays the PDF document. It contains only the document view without any additional views like outline, thumbnail bar, search, etc. Meant to be used if you want full custom implementation and design.

Summary

Constants
float DEFAULT_ZOOM Default zoom scale.
String DOCUMENTSTORE_KEY_LAST_VIEWED_PAGE_INDEX Key for storing the last viewed page index inside the DocumentDataStore of the loaded document.
float MAX_ZOOM Maximum zoom scale.
float MIN_ZOOM Min allowed zoom (before snapping back).
String PARAM_CONFIGURATION
String PARAM_IMAGE_DOCUMENT_SOURCE
String PARAM_SOURCES
Fields
public static final int DOCUMENT_VIEW_ID
Public Methods
void addAnnotationToPage(Annotation annotation, boolean selectImmediately, Runnable completeAction)
Adds annotation to page asynchronously, refreshing rendering in all UI components.
void addAnnotationToPage(Annotation annotation, boolean selectImmediately)
Adds annotation to page asynchronously, refreshing rendering in all UI components.
void addDocumentActionListener(DocumentActionListener listener)
Adds a DocumentActionListener that can handle actions bound to PDF objects.
void addDocumentListener(DocumentListener documentListener)
Adds a DocumentListener for listening to document events.
void addDocumentScrollListener(DocumentScrollListener documentScrollListener)
Adds a DocumentScrollListener for listening to scrolling events on the document.
void addDrawableProvider(PdfDrawableProvider drawableProvider)
Adds a PdfDrawableProvider to be managed by this object.
void addInsets(int leftOffset, int topOffset, int rightOffset, int bottomOffset)
Offset PdfFragment insets by specified amount.
void addOnAnnotationCreationModeChangeListener(AnnotationManager.OnAnnotationCreationModeChangeListener listener)
Register a AnnotationManager.OnAnnotationCreationModeChangeListener to get notified when annotation creation mode gets updated.
void addOnAnnotationCreationModeSettingsChangeListener(AnnotationManager.OnAnnotationCreationModeSettingsChangeListener listener)
Register a AnnotationManager.OnAnnotationCreationModeSettingsChangeListener to get notified when annotation creation settings get updated.
void addOnAnnotationDeselectedListener(AnnotationManager.OnAnnotationDeselectedListener listener)
Register a AnnotationManager.OnAnnotationDeselectedListener to get notified when annotation gets deselected.
void addOnAnnotationEditingModeChangeListener(AnnotationManager.OnAnnotationEditingModeChangeListener listener)
Register a AnnotationManager.OnAnnotationEditingModeChangeListener to get notified when annotation editing mode gets updated.
void addOnAnnotationSelectedListener(AnnotationManager.OnAnnotationSelectedListener listener)
Register a AnnotationManager.OnAnnotationSelectedListener to get notified when annotation gets selected.
void addOnAnnotationUpdatedListener(AnnotationProvider.OnAnnotationUpdatedListener listener)
Register a AnnotationProvider.OnAnnotationUpdatedListener to get notified when annotation gets updated.
void addOnFormElementClickedListener(FormManager.OnFormElementClickedListener listener)
Adds a FormManager.OnFormElementClickedListener to get notified when form element has been clicked.
void addOnFormElementDeselectedListener(FormManager.OnFormElementDeselectedListener listener)
Adds a FormManager.OnFormElementDeselectedListener to get notified when form element gets deselected.
void addOnFormElementEditingModeChangeListener(FormManager.OnFormElementEditingModeChangeListener listener)
Adds a FormManager.OnFormElementEditingModeChangeListener to get notified when form element editing mode gets updated.
void addOnFormElementSelectedListener(FormManager.OnFormElementSelectedListener listener)
Adds a FormManager.OnFormElementSelectedListener to get notified when form element gets selected.
void addOnFormElementUpdatedListener(FormManager.OnFormElementUpdatedListener listener)
Adds a FormManager.OnFormElementUpdatedListener to get notified when form element gets updated.
void addOnFormElementViewUpdatedListener(FormManager.OnFormElementViewUpdatedListener listener)
Adds a FormManager.OnFormElementViewUpdatedListener to get notified about form element view update events.
void addOnTextSelectionChangeListener(TextSelectionManager.OnTextSelectionChangeListener listener)
Adds a TextSelectionManager.OnTextSelectionChangeListener, which gets notified when text selection changes in the document, such as different text is selected.
void addOnTextSelectionModeChangeListener(TextSelectionManager.OnTextSelectionModeChangeListener listener)
Adds a TextSelectionManager.OnTextSelectionModeChangeListener, which gets notified when entering and exiting a text selection in the document.
void beginNavigation()
Notifies the navigation manager that calls to setPageIndex(int, boolean) should be added to the navigation histor until endNavigation() is called.
boolean clearSelectedAnnotations()
Clears all currently selected Annotations.
void convertPdfPointToViewPoint(PointF point, int pageIndex, boolean includeViewScroll)
Converts the coordinates stored within point from the PDF coordinate space of the given pageIndex to the view coordinate space (i.e.
void convertPdfPointToViewPoint(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.
void convertPdfRectToViewRect(RectF rect, int pageIndex)
Converts the PDF coordinates stored in rect (of the given pageIndex) to view coordinates.
void convertViewPointToPdfPoint(PointF point, int pageIndex)
Converts the coordinates stored within point from the view coordinate space (i.e.
void convertViewRectToPdfRect(RectF rect, int pageIndex)
Converts the view coordinates stored in rect to PDF coordinates on the given pageIndex.
void endNavigation()
Commits the page changes to the navigation history dropping everything but the very last one.
void enterAnnotationCreationMode()
Starts the annotation creation mode with the last used annotation tool as the selected one.
void enterAnnotationCreationMode(AnnotationTool annotationTool)
Enter annotation creation mode on the document.
void enterAnnotationEditingMode(Annotation annotation)
Enter annotation editing mode on the document.
void enterFormEditingMode(FormElement formElement)
void enterTextSelectionMode(int pageIndex, Range textRange)
Sets the current text selection.
void executeAction(Action action, ActionSender actionSender)
Executes the given PDF action on the currently loaded document.
void executeAction(Action action)
Executes the given PDF action on the currently loaded document.
void exitCurrentlyActiveMode()
Exit any currently active mode on the document (annotation creation, annotation editing, text selection).
AnnotationDefaultsManager getAnnotationDefaults()
Returns manager for annotation defaults.
AnnotationPreferencesManager getAnnotationPreferences()
Returns manager for annotation preferences.
int getBackgroundColor()
Gets the background color of the fragment.
PdfConfiguration getConfiguration()
Returns configuration for this PdfFragment.
PdfDocument getDocument()
Get the loaded document.
NavigationBackStack<NavigationItem<Integer>> getNavigationHistory()
Returns the navigation history owned by this manager.
EnumSet<AnnotationType> getOverlaidAnnotationTypes()
Gets annotation types that should be rendered as overlays.
List<Annotation> getOverlaidAnnotations()
Gets annotations that should be rendered as overlays.
int getPageCount()
Gets number of pages in the document.
int getPageIndex()
Get currently displayed document page.
Matrix getPageToViewTransformation(int pageIndex, Matrix reuse, boolean includeViewScroll)
Returns a transformation matrix for converting page coordinates (for the given pageIndex) to view coordinates (relative to the fragment itself).
Matrix getPageToViewTransformation(int pageIndex, Matrix reuse)
Returns a transformation matrix for converting page coordinates (for the given pageIndex) to view coordinates (relative to the fragment itself).
PdfPasswordView getPasswordView()
Returns currently set password view for the fragment.
List<Annotation> getSelectedAnnotations()
Returns a list of currently selected annotations, or an empty list if no annotations were selected.
FormElement getSelectedFormElement()
Returns currently selected form element.
int getSiblingPageIndex(int pageIndex)
Get page sibling index (usable in double page mode).
Bundle getState()
Get current state of the fragment.
TextSelection getTextSelection()
Returns the current text selection.
UndoManager getUndoManager()
Returns this fragment's undo manager instance for performing undo/redo operations of edits.
List<Integer> getVisiblePages()
Fetch the list of pages currently visible on the screen.
boolean getVisiblePdfRect(RectF targetRect, int pageIndex)
Sets targetRect to contain the visible PDF rect of the given pageIndex.
float getZoomScale(int pageIndex)
Get zoom scale at the specified page.
boolean isImageDocument()
Indicates whether the displayed document is an image or not.
boolean isInSpecialMode()
Returns true if any of the special modes is active.
boolean isRedactionAnnotationPreviewEnabled()
Returns redaction annotation preview mode, false by default.
boolean isScrollingEnabled()
Indicates whether the scrolling is enabled, or not.
boolean isZoomingEnabled()
Indicates whether the zooming is enabled, or not.
static PdfFragment newImageInstance(Uri documentUri, PdfConfiguration configuration)
Creates and returns a new Fragment to display a converted PDF document from a supported image format.
static PdfFragment newImageInstance(DocumentSource source, PdfConfiguration configuration)
Creates and returns a new Fragment to display a converted PDF document from a supported image format.
static PdfFragment newImageInstance(DataProvider source, PdfConfiguration configuration)
Creates and returns a new Fragment to display a converted PDF document from a supported image format.
static PdfFragment newInstance(PdfFragment fragment, PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document from an PdfFragment.
static PdfFragment newInstance(List<Uri> documentUris, PdfConfiguration configuration)
Creates and returns a new Fragment to display passed list of PDF documents as a single compound document.
static PdfFragment newInstance(List<Uri> documentUris, List<String> documentPasswords, PdfConfiguration configuration)
Creates and returns a new Fragment to display passed list of PDF documents as a single compound document.
static PdfFragment newInstance(DataProvider source, String password, String contentSignature, PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document from a custom data source
static PdfFragment newInstance(List<Uri> documentUris, List<String> documentPasswords, List<String> documentContentSignatures, PdfConfiguration configuration)
Creates and returns a new Fragment to display passed list of PDF documents as a single compound document.
static PdfFragment newInstance(DataProvider source, String password, PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document from a custom data source.
static PdfFragment newInstance(PdfDocument document, PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document from an already opened PdfDocument instance.
static PdfFragment newInstance(Uri documentUri, String password, String contentSignature, PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document.
static PdfFragment newInstance(Uri documentUri, PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document.
static PdfFragment newInstance(Uri documentUri, String password, PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document.
static PdfFragment newInstanceFromDocumentSources(List<DocumentSource> sources, PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document from the given DocumentSources.
static PdfFragment newInstanceFromSources(List<DataProvider> sources, List<String> passwords, PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document from a custom data source as a compound document.
static PdfFragment newInstanceFromSources(List<DataProvider> sources, PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document from a custom data source as a compound document.
static PdfFragment newInstanceFromSources(List<DataProvider> sources, List<String> passwords, List<String> contentSignatures, PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document from a custom data source as a compound document.
void notifyAnnotationHasChanged(Annotation annotation)
Notifies this fragment that the passed annotation has changed and that all the views displaying it should be updated.
void notifyLayoutChanged()
Notifies layout has changed and properly updates its internal state and views.
void onActivityCreated(Bundle savedInstanceState)
void onAnnotationDeselected(Annotation annotation, boolean reselected)
Called when annotation gets deselected.
void onAnnotationSelected(Annotation annotation, boolean annotationCreated)
Called when annotation gets selected.
void onAttach(Context context)
void onConfigurationChanged(Configuration newConfig)
void onCreate(Bundle savedInstanceState)
View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
void onDestroy()
void onDestroyView()
void onDetach()
boolean onDocumentClick()
Called when the user taps / clicks on the document, not the page itself but on the side (if visible).
void onDocumentLoadFailed(Throwable exception)
Called if document loading has failed.
void onDocumentLoaded(PdfDocument document)
Called when document is successfully loaded and the document view has been laid out.
boolean onDocumentSave(PdfDocument document, DocumentSaveOptions saveOptions)
Called before document will be saved.
void onDocumentSaveCancelled(PdfDocument document)
Called if document saving has been cancelled.
void onDocumentSaveFailed(PdfDocument document, Throwable exception)
Called if document saving has failed.
void onDocumentSaved(PdfDocument document)
Called after the document has been saved.
void onDocumentScrolled(PdfFragment fragment, int currX, int currY, int maxX, int maxY, int extendX, int extendY)
Called whenever the document in the fragment scrolled.
void onDocumentZoomed(PdfDocument document, int pageIndex, float scaleFactor)
Called when a user zooms a document.
void onFormElementDeselected(FormElement formElement, boolean reselected)
Called when form element gets deselected.
void onFormElementSelected(FormElement formElement)
Called when form element gets selected.
void onLowMemory()
void onPageChanged(PdfDocument document, int pageIndex)
Called when user scrolled to a new page.
boolean onPageClick(PdfDocument document, int pageIndex, MotionEvent event, PointF pagePosition, Annotation clickedAnnotation)
Called when user taps / clicks on the page.
void onPageUpdated(PdfDocument document, int pageIndex)
Called when content of page with pageIndex has changed (for example due to annotation or form field being updated).
boolean onPrepareAnnotationSelection(AnnotationSelectionController controller, Annotation annotation, boolean annotationCreated)
Called immediately before annotation is going to be selected.
void onResume()
void onSaveInstanceState(Bundle outState)
Called by the activity if it requires the fragment to save its state.
void onScrollStateChanged(PdfFragment fragment, ScrollState state)
Called whenever the current scroll state of the PdfFragment changed.
void onStop()
void removeDocumentActionListener(DocumentActionListener listener)
Removes a previously added DocumentActionListener that can handle actions bound to PDF objects.
void removeDocumentListener(DocumentListener documentListener)
Removes a previously registered DocumentListener.
void removeDocumentScrollListener(DocumentScrollListener documentScrollListener)
Removes a previously registered DocumentScrollListener.
void removeDrawableProvider(PdfDrawableProvider drawableProvider)
Removes a previously added PdfDrawableProvider.
void removeOnAnnotationCreationModeChangeListener(AnnotationManager.OnAnnotationCreationModeChangeListener listener)
void removeOnAnnotationCreationModeSettingsChangeListener(AnnotationManager.OnAnnotationCreationModeSettingsChangeListener listener)
void removeOnAnnotationDeselectedListener(AnnotationManager.OnAnnotationDeselectedListener listener)
Remove a previously registered AnnotationManager.OnAnnotationDeselectedListener.
void removeOnAnnotationEditingModeChangeListener(AnnotationManager.OnAnnotationEditingModeChangeListener listener)
void removeOnAnnotationSelectedListener(AnnotationManager.OnAnnotationSelectedListener listener)
Remove a previously registered AnnotationManager.OnAnnotationSelectedListener.
void removeOnAnnotationUpdatedListener(AnnotationProvider.OnAnnotationUpdatedListener listener)
Remove a previously registered AnnotationProvider.OnAnnotationUpdatedListener.
void removeOnFormElementClickedListener(FormManager.OnFormElementClickedListener listener)
Removes a previously registered FormManager.OnFormElementClickedListener.
void removeOnFormElementDeselectedListener(FormManager.OnFormElementDeselectedListener listener)
Removes a previously registered FormManager.OnFormElementDeselectedListener.
void removeOnFormElementEditingModeChangeListener(FormManager.OnFormElementEditingModeChangeListener listener)
Removes a previously registered FormManager.OnFormElementEditingModeChangeListener.
void removeOnFormElementSelectedListener(FormManager.OnFormElementSelectedListener listener)
Removes a previously registered FormManager.OnFormElementSelectedListener.
void removeOnFormElementUpdatedListener(FormManager.OnFormElementUpdatedListener listener)
Removes a previously registered FormManager.OnFormElementUpdatedListener.
void removeOnFormElementViewUpdatedListener(FormManager.OnFormElementViewUpdatedListener listener)
Removes a previously registered FormManager.OnFormElementViewUpdatedListener.
void removeOnTextSelectionChangeListener(TextSelectionManager.OnTextSelectionChangeListener listener)
Removes a TextSelectionManager.OnTextSelectionChangeListener, which gets notified when text selection changes in the document, such as different text is selected.
void removeOnTextSelectionModeChangeListener(TextSelectionManager.OnTextSelectionModeChangeListener listener)
Removes a previously added TextSelectionManager.OnTextSelectionModeChangeListener, which gets notified when entering and exiting a text selection in the document.
void save()
Saves the file held by the document view back to it's original location.
void scrollTo(RectF pdfRect, int pageIndex, long duration, boolean scrollWhenVisible)
Scrolls to the given pdfRect, if necessary changing to the page.
void setAnnotationDefaultsProvider(AnnotationType annotationType, AnnotationDefaultsProvider defaultsProvider)
Configures annotation defaults provider for given annotation type.
void setBackgroundColor(int backgroundColor)
Sets the background color of the fragment.
void setCustomPdfSource(DocumentSource source)
Sets the custom source for the PDF file.
void setCustomPdfSources(List<DocumentSource> sources)
Sets the custom sources for the PDF file.
void setDocumentSigningListener(DocumentSigningListener documentSigningListener)
Sets a new DocumentSigningListener or replaces an existing one.
void setInsets(int left, int top, int right, int bottom)
Set insets that will be used as padding for PdfFragment contents.
void setOnDocumentLongPressListener(OnDocumentLongPressListener listener)
Set a OnDocumentLongPressListener for long press document events.
void setOnPreparePopupToolbarListener(OnPreparePopupToolbarListener listener)
Sets the listener that will allow you to get notified when each of the popup toolbars is prepared and ready to be displayed.
void setOverlaidAnnotationTypes(EnumSet<AnnotationType> overlayAnnotationTypes)
Sets annotation types that should be rendered as overlays.
void setOverlaidAnnotations(List<Annotation> overlayAnnotations)
Sets annotations that should be rendered as overlays.
void setPageIndex(int pageIndex)
Sets the pageIndex to be displayed (0 is the first one), using our default decision on animating, which is to animate the transition if the page is next/before the current page, and not animate if further away.
void setPageIndex(int pageIndex, boolean animated)
Sets the pageIndex to be displayed (0 is the first one).
void setPageLoadingDrawable(Drawable drawable)
Sets drawable that should be displayed instead of fragment's contents (i.e.
void setPasswordView(PdfPasswordView pdfPasswordView)
Sets password view to be used for the password-protected documents.
void setRedactionAnnotationPreviewEnabled(boolean enable)
Sets redaction annotations preview as redacted.
void setScrollingEnabled(boolean enabled)
Enables/disabled the scrolling performed by the user.
void setSelectedAnnotation(Annotation annotation)
Selects a single Annotation.
void setSelectedAnnotations(Collection<Annotation> annotations)
Sets the currently selected Annotations.
void setSelectedFormElement(FormElement formElement)
Sets the currently selected FormElement.
void setState(Bundle state)
Replace fragment state.
void setZoomingEnabled(boolean enabled)
Enables/disabled the zooming performed by the user.
void zoomBy(int focusX, int focusY, int pageIndex, float scaleFactor, long duration)
Zoom by the given scale focused on the given point in PDF coordinates.`
void zoomTo(int focusX, int focusY, int pageIndex, float targetScale, long duration)
Zoom to the given scale focused on the given point in PDF coordinates.
void zoomTo(RectF rect, int pageIndex, long duration)
Zoom to a specific rect on the given page.
[Expand]
Inherited Methods
From class android.support.v4.app.Fragment
From class java.lang.Object
From interface android.arch.lifecycle.LifecycleOwner
From interface android.arch.lifecycle.ViewModelStoreOwner
From interface android.content.ComponentCallbacks
From interface android.view.View.OnCreateContextMenuListener
From interface com.pspdfkit.annotations.actions.ActionResolver
From interface com.pspdfkit.framework.document.DocumentSaver.DocumentSaveListener
From interface com.pspdfkit.framework.model.InternalPdfDocument.InternalDocumentListener
From interface com.pspdfkit.framework.views.document.SpecialModeManager
From interface com.pspdfkit.listeners.DocumentListener
From interface com.pspdfkit.listeners.scrolling.DocumentScrollListener
From interface com.pspdfkit.ui.drawable.PdfDrawableManager
From interface com.pspdfkit.ui.navigation.PageNavigator
From interface com.pspdfkit.ui.special_mode.manager.AnnotationManager
From interface com.pspdfkit.ui.special_mode.manager.AnnotationManager.OnAnnotationDeselectedListener
From interface com.pspdfkit.ui.special_mode.manager.AnnotationManager.OnAnnotationSelectedListener
From interface com.pspdfkit.ui.special_mode.manager.FormManager
From interface com.pspdfkit.ui.special_mode.manager.FormManager.OnFormElementDeselectedListener
From interface com.pspdfkit.ui.special_mode.manager.FormManager.OnFormElementSelectedListener
From interface com.pspdfkit.ui.special_mode.manager.TextSelectionManager

Constants

public static final float DEFAULT_ZOOM

Default zoom scale.

Constant Value: 1.0

public static final String DOCUMENTSTORE_KEY_LAST_VIEWED_PAGE_INDEX

Key for storing the last viewed page index inside the DocumentDataStore of the loaded document. The last viewed page index is only read or written if isLastViewedPageRestorationEnabled() is set to true. If page restoration is disabled, the fragment won't access or modify the document store and any previously written value. The value is saved to the store inside onStop().

Constant Value: "PSPDFKit.lastViewedPage"

public static final float MAX_ZOOM

Maximum zoom scale.

Constant Value: 15.0

public static final float MIN_ZOOM

Min allowed zoom (before snapping back).

Constant Value: 0.8

public static final String PARAM_CONFIGURATION

Constant Value: "PSPDFKit.Configuration"

public static final String PARAM_IMAGE_DOCUMENT_SOURCE

Constant Value: "PSPDFKit.ImageDocument.Source"

public static final String PARAM_SOURCES

Constant Value: "PSPDFKit.Sources"

Fields

public static final int DOCUMENT_VIEW_ID

Public Methods

public void addAnnotationToPage (Annotation annotation, boolean selectImmediately, Runnable completeAction)

Adds annotation to page asynchronously, refreshing rendering in all UI components.

Parameters
annotation The Annotation to add.
selectImmediately True when annotation should be selected for editing immediately after being added to the page. This also enters annotation editing mode via enterAnnotationEditingMode(Annotation).
completeAction Action that should be executed immediately after annotation has been added to the page.

public void addAnnotationToPage (Annotation annotation, boolean selectImmediately)

Adds annotation to page asynchronously, refreshing rendering in all UI components.

Parameters
annotation The Annotation to add.
selectImmediately True when annotation should be selected for editing immediately after being added to the page. This also enters annotation editing mode via enterAnnotationEditingMode(Annotation).

public void addDocumentActionListener (DocumentActionListener listener)

Adds a DocumentActionListener that can handle actions bound to PDF objects. If the listener has already been added previously, this method will be a no-op. Adding null is not allowed, and will result in an exception.

Parameters
listener DocumentActionListener that should be notified. Must be non-null.

public void addDocumentListener (DocumentListener documentListener)

Adds a DocumentListener for listening to document events. If the listener has already been added previously, this method will be a no-op. Listeners registered with this method will be unregistered automatically in onDetach(). Passing null is not allowed, and will result in an exception.

Parameters
documentListener Listener to be notified of document events. May not be null.

public void addDocumentScrollListener (DocumentScrollListener documentScrollListener)

Adds a DocumentScrollListener for listening to scrolling events on the document. If the listener has already been added previously, this method will be a no-op. Listeners registered with this method will be unregistered automatically in onDetach(). Passing null is not allowed, and will result in an exception.

Parameters
documentScrollListener Listener to be notified of document scroll events. May not be null.

public void addDrawableProvider (PdfDrawableProvider drawableProvider)

Adds a PdfDrawableProvider to be managed by this object. If the provider has been added previously, this method will be a no-op. Adding null is not allowed, and will result in an exception.

Parameters
drawableProvider PdfDrawableProvider whose drawable instances should be managed (e.g. rendered on screen).

public void addInsets (int leftOffset, int topOffset, int rightOffset, int bottomOffset)

Offset PdfFragment insets by specified amount.

Parameters
leftOffset The left inset offset in pixels.
topOffset The top inset offset in pixels.
rightOffset The right inset offset in pixels.
bottomOffset The bottom inset offset in pixels.

public void addOnAnnotationCreationModeChangeListener (AnnotationManager.OnAnnotationCreationModeChangeListener listener)

Register a AnnotationManager.OnAnnotationCreationModeChangeListener to get notified when annotation creation mode gets updated. If the provider has been registered previously, this method will be a no-op.

Parameters
listener Listener to register. Must be non-null.

public void addOnAnnotationCreationModeSettingsChangeListener (AnnotationManager.OnAnnotationCreationModeSettingsChangeListener listener)

Register a AnnotationManager.OnAnnotationCreationModeSettingsChangeListener to get notified when annotation creation settings get updated. If the provider has been registered previously, this method will be a no-op.

Parameters
listener Listener to register. Must be non-null.

public void addOnAnnotationDeselectedListener (AnnotationManager.OnAnnotationDeselectedListener listener)

Register a AnnotationManager.OnAnnotationDeselectedListener to get notified when annotation gets deselected. If the provider has been registered previously, this method will be a no-op.

Parameters
listener Listener to register. Must be non-null.

public void addOnAnnotationEditingModeChangeListener (AnnotationManager.OnAnnotationEditingModeChangeListener listener)

Register a AnnotationManager.OnAnnotationEditingModeChangeListener to get notified when annotation editing mode gets updated. If the provider has been registered previously, this method will be a no-op.

Parameters
listener Listener to register. Must be non-null.

public void addOnAnnotationSelectedListener (AnnotationManager.OnAnnotationSelectedListener listener)

Register a AnnotationManager.OnAnnotationSelectedListener to get notified when annotation gets selected. If the provider has been registered previously, this method will be a no-op.

Parameters
listener Listener to register. Must be non-null.

public void addOnAnnotationUpdatedListener (AnnotationProvider.OnAnnotationUpdatedListener listener)

Register a AnnotationProvider.OnAnnotationUpdatedListener to get notified when annotation gets updated. If the listener has been registered previously, this method will be a no-op.

Note: Listeners methods are dispatched on the main UI thread.

Parameters
listener Listener to register. Must be non-null.

public void addOnFormElementClickedListener (FormManager.OnFormElementClickedListener listener)

Adds a FormManager.OnFormElementClickedListener to get notified when form element has been clicked. If the listener has already been added previously, this method will be a no-op. Adding null is not allowed, and will result in an exception.

Parameters
listener OnFormElementClickedListener that should be notified. Must be non-null.

public void addOnFormElementDeselectedListener (FormManager.OnFormElementDeselectedListener listener)

Adds a FormManager.OnFormElementDeselectedListener to get notified when form element gets deselected. If the listener has already been added previously, this method will be a no-op. Adding null is not allowed, and will result in an exception.

Parameters
listener OnFormElementDeselectedListener that should be notified. Must be non-null.

public void addOnFormElementEditingModeChangeListener (FormManager.OnFormElementEditingModeChangeListener listener)

Adds a FormManager.OnFormElementEditingModeChangeListener to get notified when form element editing mode gets updated. If the listener has already been added previously, this method will be a no-op. Adding null is not allowed, and will result in an exception.

Parameters
listener OnFormElementEditingModeChangeListener that should be notified. Must be non-null.

public void addOnFormElementSelectedListener (FormManager.OnFormElementSelectedListener listener)

Adds a FormManager.OnFormElementSelectedListener to get notified when form element gets selected. If the listener has already been added previously, this method will be a no-op. Adding null is not allowed, and will result in an exception.

Parameters
listener OnFormElementSelectedListener that should be notified. Must be non-null.

public void addOnFormElementUpdatedListener (FormManager.OnFormElementUpdatedListener listener)

Adds a FormManager.OnFormElementUpdatedListener to get notified when form element gets updated. If the listener has already been added previously, this method will be a no-op. Adding null is not allowed, and will result in an exception.

Parameters
listener OnFormElementUpdatedListener that should be notified. Must be non-null.

public void addOnFormElementViewUpdatedListener (FormManager.OnFormElementViewUpdatedListener listener)

Adds a FormManager.OnFormElementViewUpdatedListener to get notified about form element view update events. If the listener has already been added previously, this method will be a no-op. Adding null is not allowed, and will result in an exception.

Parameters
listener OnFormElementViewUpdatedListener that should be notified. Must be non-null.

public void addOnTextSelectionChangeListener (TextSelectionManager.OnTextSelectionChangeListener listener)

Adds a TextSelectionManager.OnTextSelectionChangeListener, which gets notified when text selection changes in the document, such as different text is selected. If the listener has already been added previously, this method will be a no-op. Adding null is not allowed, and will result in an exception.

Parameters
listener Listener to register. Must be non-null.

public void addOnTextSelectionModeChangeListener (TextSelectionManager.OnTextSelectionModeChangeListener listener)

Adds a TextSelectionManager.OnTextSelectionModeChangeListener, which gets notified when entering and exiting a text selection in the document. If the listener has already been added previously, this method will be a no-op. Adding null is not allowed, and will result in an exception.

Parameters
listener OnTextSelectionModeChangeListener. Must be non-null.

public void beginNavigation ()

Notifies the navigation manager that calls to setPageIndex(int, boolean) should be added to the navigation histor until endNavigation() is called.

public boolean clearSelectedAnnotations ()

Clears all currently selected Annotations. This method may only be called on the main thread (UI thread).

Returns
  • true if the the selection has been cleared.

public void convertPdfPointToViewPoint (PointF point, int pageIndex, boolean includeViewScroll)

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).
includeViewScroll If true include document view scroll and page position into the calculations.

public void convertPdfPointToViewPoint (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 void convertPdfRectToViewRect (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).

public void convertViewPointToPdfPoint (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 void convertViewRectToPdfRect (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 void endNavigation ()

Commits the page changes to the navigation history dropping everything but the very last one.

public void enterAnnotationCreationMode ()

Starts the annotation creation mode with the last used annotation tool as the selected one.

Additionally, annotation creator dialog will show up if the default annotation creator has not been set.

public void enterAnnotationCreationMode (AnnotationTool annotationTool)

Enter annotation creation mode on the document. Once you invoke this method, you'll get AnnotationCreationController (through registered OnAnnotationCreationModeChangeListener) which provides methods for annotation creation with a specified type.

Additionally, annotation creator dialog will show up if the default annotation creator has not been set.

Parameters
annotationTool Annotation tool to activate once creation mode is entered. Use NONE to just enter creation mode without any annotation creation tool selected.

public void enterAnnotationEditingMode (Annotation annotation)

Enter annotation editing mode on the document. Once you invoke this method, you'll get AnnotationEditingController (through registered OnAnnotationEditingModeChangeListener) which provides methods for editing a selected annotation. Notice: this method will not select annotation on the screen, for that use setSelectedAnnotation(Annotation).

Parameters
annotation Annotation to be edited.

public void enterFormEditingMode (FormElement formElement)

public void enterTextSelectionMode (int pageIndex, Range textRange)

Sets the current text selection. Once you invoke this method, you'll get TextSelectionController (through registered OnTextSelectionModeChangeListener) which provides methods for managing text selection actions.

Parameters
pageIndex Number of the page on which text selection should be performed. Has to be 0 <= pageIndex < totalPages.
textRange 0-based range spanning the text which should be selected. Range has to be in the interval [0, textLength].
Throws
IllegalArgumentException If pageIndex is not in the page range.

public void executeAction (Action action, ActionSender actionSender)

Executes the given PDF action on the currently loaded document.

Parameters
action Action to be executed.
actionSender Optional sender that triggered execution of this action.

public void executeAction (Action action)

Executes the given PDF action on the currently loaded document.

Parameters
action Action that should be executed.

public void exitCurrentlyActiveMode ()

Exit any currently active mode on the document (annotation creation, annotation editing, text selection).

public AnnotationDefaultsManager getAnnotationDefaults ()

Returns manager for annotation defaults.

Returns
  • The annotation defaults manager of this fragment.

public AnnotationPreferencesManager getAnnotationPreferences ()

Returns manager for annotation preferences.

Returns
  • The annotation preferences manager of this fragment.

public int getBackgroundColor ()

Gets the background color of the fragment. It's the background of the area behind the pages.

Returns
  • Background color of the area behind the pages.

public PdfConfiguration getConfiguration ()

Returns configuration for this PdfFragment.

Returns
  • A page rendering configuration for this fragment.

public PdfDocument getDocument ()

Get the loaded document.

Returns
  • Document loaded into the fragment.

public NavigationBackStack<NavigationItem<Integer>> getNavigationHistory ()

Returns the navigation history owned by this manager.

Returns

public EnumSet<AnnotationType> getOverlaidAnnotationTypes ()

Gets annotation types that should be rendered as overlays.

Returns
  • Set of annotation types that are enabled for overlay rendering.

public List<Annotation> getOverlaidAnnotations ()

Gets annotations that should be rendered as overlays.

Returns
  • List of annotations that should be rendered as overlays.

public int getPageCount ()

Gets number of pages in the document.

Returns
  • Number of pages in the displayed document, -1 if document is null.

public int getPageIndex ()

Get currently displayed document page.

Returns
  • Currently displayed document page, -1 if document is null.

public Matrix getPageToViewTransformation (int pageIndex, Matrix reuse, boolean includeViewScroll)

Returns a transformation matrix for converting page coordinates (for the given pageIndex) to view coordinates (relative to the fragment itself). The returned matrix can be inverted using invert(Matrix) to create a view-to-page conversion matrix.

Parameters
pageIndex Number of the page for which to retrieve the transformation (starting at code).
reuse A matrix object to reuse for calculation. May be null if a new matrix should be created.
includeViewScroll If true include document view scroll and page position into the calculations.
Returns
  • Transformation matrix for converting page coordinates to view coordinates. The method may return null, 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 Matrix getPageToViewTransformation (int pageIndex, Matrix reuse)

Returns a transformation matrix for converting page coordinates (for the given pageIndex) to view coordinates (relative to the fragment itself). The returned matrix can be inverted using invert(Matrix) to create a view-to-page conversion matrix.

Parameters
pageIndex Number of the page for which to retrieve the transformation (starting at code).
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. The method may return null, 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 PdfPasswordView getPasswordView ()

Returns currently set password view for the fragment.

Returns
  • password view currently set on the fragment.

public List<Annotation> getSelectedAnnotations ()

Returns a list of currently selected annotations, or an empty list if no annotations were selected.

Returns
  • A list of selected annotations, or an empty list if no annotations were were selected.

public FormElement getSelectedFormElement ()

Returns currently selected form element.

Returns
  • Currently selected form element, null if no element is selected.

public int getSiblingPageIndex (int pageIndex)

Get page sibling index (usable in double page mode).

Parameters
pageIndex Index of the page for which we look for the sibling.
Returns
  • Provided page sibling, or -1 if there is none.

public Bundle getState ()

Get current state of the fragment.

Returns
  • Fragment's state or null if views are not ready yet.

public TextSelection getTextSelection ()

Returns the current text selection.

Returns
  • Current text selection, or null if no text is selected.

public UndoManager getUndoManager ()

Returns this fragment's undo manager instance for performing undo/redo operations of edits.

Returns
  • UndoManager used for handling undo/redo operations on this fragment.

public List<Integer> getVisiblePages ()

Fetch the list of pages currently visible on the screen.

Returns
  • List of page numbers of visible pages.

public boolean getVisiblePdfRect (RectF targetRect, int pageIndex)

Sets targetRect to contain the visible PDF rect of the given pageIndex. If the pageIndex is not visible on the screen, targetRect won't be modified and the method will return false.

Parameters
targetRect RectF instance which will be set to the visible PDF rect.
pageIndex Target page number. 0-based index.
Returns
  • true if the page visible and its visible rect was written to targetRect, or false if the page is not visible and targetRect was not modified.

public float getZoomScale (int pageIndex)

Get zoom scale at the specified page.

Parameters
pageIndex Target page number.
Returns
  • Current zoom scale on the page if layout is ready, if not - the default zoom scale set in the configuration.

public boolean isImageDocument ()

Indicates whether the displayed document is an image or not.

Returns
  • true if the displayed document is image, false otherwise.

public boolean isInSpecialMode ()

Returns true if any of the special modes is active.

Returns
  • true when fragment is in a special mode - i.e. it has text, annotation or form selection is active or when annotation creation is in progress.

public boolean isRedactionAnnotationPreviewEnabled ()

Returns redaction annotation preview mode, false by default.

Returns
  • true if redaction annotation preview mode is enabled, false otherwise.

public boolean isScrollingEnabled ()

Indicates whether the scrolling is enabled, or not.

Returns
  • true if scrolling is enabled, false otherwise.

public boolean isZoomingEnabled ()

Indicates whether the zooming is enabled, or not.

Returns
  • true if zooming is enabled, false otherwise.

public static PdfFragment newImageInstance (Uri documentUri, PdfConfiguration configuration)

Creates and returns a new Fragment to display a converted PDF document from a supported image format.

Parameters
documentUri android.net.Uri pointing to the image document to open.
configuration Configuration for the image document to display generated with PdfConfiguration.Builder, or getDefaultImageDocumentConfiguration().
Returns
  • New instance of fragment that can be attached to view hierarchy.

public static PdfFragment newImageInstance (DocumentSource source, PdfConfiguration configuration)

Creates and returns a new Fragment to display a converted PDF document from a supported image format.

Parameters
source Document source to load the image from
configuration Configuration for the image document to display generated with PdfConfiguration.Builder, or getDefaultImageDocumentConfiguration().
Returns
  • New instance of fragment that can be attached to view hierarchy.

public static PdfFragment newImageInstance (DataProvider source, PdfConfiguration configuration)

Creates and returns a new Fragment to display a converted PDF document from a supported image format.

Parameters
source Instance of DataProvider to load the image from. Note: this object WILL NOT BE RETAINED ON RECREATION unless it implements Parcelable interface.
configuration Configuration for the image document to display generated with PdfConfiguration.Builder, or getDefaultImageDocumentConfiguration().
Returns
  • New instance of fragment that can be attached to view hierarchy.

public static PdfFragment newInstance (PdfFragment fragment, PdfConfiguration configuration)

Creates and returns a new Fragment to display a PDF document from an PdfFragment. This will copy the state of the given Fragment while applying the new configuration.

Parameters
fragment An already displayed PdfFragment to copy the state from.
configuration Configuration for PDF display generated with PdfConfiguration.Builder.
Returns
  • New instance of fragment that can be attached to view hierarchy.

public static PdfFragment newInstance (List<Uri> documentUris, PdfConfiguration configuration)

Creates and returns a new Fragment to display passed list of PDF documents as a single compound document.

Parameters
documentUris pointing to the document to open.
configuration Configuration for PDF display generated with PdfConfiguration.Builder.
Returns
  • New instance of fragment that can be attached to view hierarchy.

public static PdfFragment newInstance (List<Uri> documentUris, List<String> documentPasswords, PdfConfiguration configuration)

Creates and returns a new Fragment to display passed list of PDF documents as a single compound document.

Parameters
documentUris pointing to the document to open.
documentPasswords A list of corresponding passwords for the given documents.
configuration Configuration for PDF display generated with PdfConfiguration.Builder.
Returns
  • New instance of fragment that can be attached to view hierarchy.

public static PdfFragment newInstance (DataProvider source, String password, String contentSignature, PdfConfiguration configuration)

Creates and returns a new Fragment to display a PDF document from a custom data source

Parameters
source Instance of DataProvider to load data from. Note: this object WILL NOT BE RETAINED ON RECREATION unless it implements Parcelable interface.
password Document password, can be null.
contentSignature Content signature, can be null.
configuration Configuration for PDF display generated with PdfConfiguration.Builder.
Returns
  • New instance of fragment that can be attached to view hierarchy.

public static PdfFragment newInstance (List<Uri> documentUris, List<String> documentPasswords, List<String> documentContentSignatures, PdfConfiguration configuration)

Creates and returns a new Fragment to display passed list of PDF documents as a single compound document.

Parameters
documentUris pointing to the document to open.
documentPasswords A list of corresponding passwords for the given documents.
documentContentSignatures A list of corresponding document content signatures for the given documents.
configuration Configuration for PDF display generated with PdfConfiguration.Builder.
Returns
  • New instance of Fragment that can be attached to view hierarchy.

public static PdfFragment newInstance (DataProvider source, String password, PdfConfiguration configuration)

Creates and returns a new Fragment to display a PDF document from a custom data source.

Parameters
source Instance of DataProvider to load data from. Note: this object WILL NOT BE RETAINED ON RECREATION unless it implements Parcelable interface.
password Document password, can be null.
configuration Configuration for PDF display generated with PdfConfiguration.Builder.
Returns
  • New instance of fragment that can be attached to view hierarchy.

public static PdfFragment newInstance (PdfDocument document, PdfConfiguration configuration)

Creates and returns a new Fragment to display a PDF document from an already opened PdfDocument instance. This will not reload the document.

Parameters
document An already opened instance of a PdfDocument object.
configuration Configuration for PDF display generated with PdfConfiguration.Builder.
Returns
  • New instance of fragment that can be attached to view hierarchy.

public static PdfFragment newInstance (Uri documentUri, String password, String contentSignature, PdfConfiguration configuration)

Creates and returns a new Fragment to display a PDF document.

Parameters
documentUri pointing to the document to open
password Document password, can be null.
contentSignature Content signature, can be null.
configuration Configuration for PDF display generated with PdfConfiguration.Builder.
Returns
  • New instance of fragment that can be attached to view hierarchy.

public static PdfFragment newInstance (Uri documentUri, PdfConfiguration configuration)

Creates and returns a new Fragment to display a PDF document.

Parameters
documentUri pointing to the document to open.
configuration Configuration for PDF display generated with PdfConfiguration.Builder.
Returns
  • New instance of fragment that can be attached to view hierarchy.

public static PdfFragment newInstance (Uri documentUri, String password, PdfConfiguration configuration)

Creates and returns a new Fragment to display a PDF document.

Parameters
documentUri pointing to the document to open.
password Document password, can be null.
configuration Configuration for PDF display generated with PdfConfiguration.Builder.
Returns
  • New instance of fragment that can be attached to view hierarchy.

public static PdfFragment newInstanceFromDocumentSources (List<DocumentSource> sources, PdfConfiguration configuration)

Creates and returns a new Fragment to display a PDF document from the given DocumentSources.

Parameters
sources List of DocumentSources to load data from.
configuration Configuration for PDF display generated with PdfConfiguration.Builder.
Returns
  • New instance of fragment that can be attached to view hierarchy.

public static PdfFragment newInstanceFromSources (List<DataProvider> sources, List<String> passwords, PdfConfiguration configuration)

Creates and returns a new Fragment to display a PDF document from a custom data source as a compound document.

Parameters
sources List of DataProviders to load data from. Note: this object WILL NOT BE RETAINED ON RECREATION unless it implements Parcelable interface.
passwords Document password, can be null.
configuration Configuration for PDF display generated with PdfConfiguration.Builder.
Returns
  • New instance of fragment that can be attached to view hierarchy.

public static PdfFragment newInstanceFromSources (List<DataProvider> sources, PdfConfiguration configuration)

Creates and returns a new Fragment to display a PDF document from a custom data source as a compound document.

Parameters
sources List of DataProviders to load data from. Note: this object WILL NOT BE RETAINED ON RECREATION unless it implements Parcelable interface.
configuration Configuration for PDF display generated with PdfConfiguration.Builder.
Returns
  • New instance of fragment that can be attached to view hierarchy.

public static PdfFragment newInstanceFromSources (List<DataProvider> sources, List<String> passwords, List<String> contentSignatures, PdfConfiguration configuration)

Creates and returns a new Fragment to display a PDF document from a custom data source as a compound document.

Parameters
sources List of DataProviders to load data from. Note: this object WILL NOT BE RETAINED ON RECREATION unless it implements Parcelable interface.
passwords Document password, can be null.
contentSignatures Content signature, can be null.
configuration Configuration for PDF display generated with PdfConfiguration.Builder.
Returns
  • New instance of fragment that can be attached to view hierarchy.

public void notifyAnnotationHasChanged (Annotation annotation)

Notifies this fragment that the passed annotation has changed and that all the views displaying it should be updated. Calling this method before document is loaded will have no effect.

Parameters
annotation Annotation that has changed.

public void notifyLayoutChanged ()

Notifies layout has changed and properly updates its internal state and views. Call this when PdfFragment is embedded in a ViewGroup that has changed its size, this will schedule a layout pass of the view tree, after views have been laid out.

public void onActivityCreated (Bundle savedInstanceState)

public void onAnnotationDeselected (Annotation annotation, boolean reselected)

Called when annotation gets deselected.

Parameters
annotation Annotation that is being deselected.
reselected true if annotation is being reselected (another annotation will be selected soon).

public void onAnnotationSelected (Annotation annotation, boolean annotationCreated)

Called when annotation gets selected.

Parameters
annotation Annotation that is being selected.
annotationCreated true if selected annotation is being created in PageModeHandler.

public void onAttach (Context context)

public void onConfigurationChanged (Configuration newConfig)

public void onCreate (Bundle savedInstanceState)

public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

public void onDestroy ()

public void onDestroyView ()

public void onDetach ()

public boolean onDocumentClick ()

Called when the user taps / clicks on the document, not the page itself but on the side (if visible).

Returns
  • true if tap is handled or false if PSPDFKit should execute it's default action.

public void onDocumentLoadFailed (Throwable exception)

Called if document loading has failed.

Parameters
exception Cause of the loading failure.

public void onDocumentLoaded (PdfDocument document)

Called when document is successfully loaded and the document view has been laid out.

Parameters
document Loaded document instance.

public boolean onDocumentSave (PdfDocument document, DocumentSaveOptions saveOptions)

Called before document will be saved. This callback allows cancellation of the save process.

Parameters
document Instance of document to be saved.
saveOptions Save options to be applied to the document. You may change parameters on this object to control how document is saved.
Returns
  • true if the document should be saved, false if saving should be cancelled.

public void onDocumentSaveCancelled (PdfDocument document)

Called if document saving has been cancelled.

Parameters
document Instance of document that was saved.

public void onDocumentSaveFailed (PdfDocument document, Throwable exception)

Called if document saving has failed.

Parameters
exception Cause of the saving failure if applicable.

public void onDocumentSaved (PdfDocument document)

Called after the document has been saved.

Parameters
document Instance of document that was saved.

public void onDocumentScrolled (PdfFragment fragment, int currX, int currY, int maxX, int maxY, int extendX, int extendY)

Called whenever the document in the fragment scrolled. Values are expressed in an arbitrary unit and may change with every call. Also maxX and maxY are not guaranteed to remain the same between two calls.

Parameters
fragment The scrolled PdfFragment.
currX Current scroll amount X.
currY Current scroll amount Y.
maxX Maximum scroll amount of the X dimension.
maxY Maximum scroll amount of the Y dimension.
extendX Extend of the visible content in the X dimension.
extendY Extend of the visible content in the Y dimension.

public void onDocumentZoomed (PdfDocument document, int pageIndex, float scaleFactor)

Called when a user zooms a document.

Parameters
document Current document.
pageIndex The number of the page that the was zoomed.
scaleFactor The current scale factor.

public void onFormElementDeselected (FormElement formElement, boolean reselected)

Called when form element gets deselected.

Parameters
formElement Form element that is being deselected.
reselected true if form element is being reselected (another form element will be selected soon).

public void onFormElementSelected (FormElement formElement)

Called when form element gets selected.

Parameters
formElement Form element that is being selected.

public void onLowMemory ()

public void onPageChanged (PdfDocument document, int pageIndex)

Called when user scrolled to a new page.

Parameters
document Currently opened document.
pageIndex Page number of new page.

public boolean onPageClick (PdfDocument document, int pageIndex, MotionEvent event, PointF pagePosition, Annotation clickedAnnotation)

Called when user taps / clicks on the page.

Parameters
document Currently opened document.
pageIndex Page number of the page being tapped.
event MotionEvent that triggered this page click. May be null if this page click was triggered from keyboard or accessibility event.
pagePosition Tapped page position (in PDF page coordinates with origin on bottom left). Coordinates passed here may exceed the page size (which is returned by getPageSize(int)) and can also be negative. If the click was triggered by the keyboard, pagePosition will be null.
clickedAnnotation Annotation that was tapped, or null if no annotation was tapped.
Returns
  • true if tap was handled by this DocumentListener and should not be handled by PSPDFKit anymore. If returning false PSPDFKit will continue executing it's default action.

public void onPageUpdated (PdfDocument document, int pageIndex)

Called when content of page with pageIndex has changed (for example due to annotation or form field being updated). All views displaying this page need to refresh.

Parameters
pageIndex Page index of the updated page.

public boolean onPrepareAnnotationSelection (AnnotationSelectionController controller, Annotation annotation, boolean annotationCreated)

Called immediately before annotation is going to be selected.

Parameters
controller Selection controller that is performing the selection.
annotation Annotation that is going to be selected.
annotationCreated True when annotation is
Returns

public void onResume ()

public void onSaveInstanceState (Bundle outState)

Called by the activity if it requires the fragment to save its state. Since this method can also be called when the fragment is on the backstack and has no view, this method may not rely on any views being present at the time of calling.

public void onScrollStateChanged (PdfFragment fragment, ScrollState state)

Called whenever the current scroll state of the PdfFragment changed.

Parameters
fragment PdfFragment whose scroll state changed.
state The new scroll state.

public void onStop ()

public void removeDocumentActionListener (DocumentActionListener listener)

Removes a previously added DocumentActionListener that can handle actions bound to PDF objects. Upon calling this method the listener will no longer be notified of any changes. If the listener has not been added, this method will be a no-op. Adding null is not allowed, and will result in an exception.

Parameters
listener DocumentActionListener that should be removed. Must be non-null.

public void removeDocumentListener (DocumentListener documentListener)

Removes a previously registered DocumentListener. After calling this method the documentListener will stop receiving document events. If the listener has not been added previously, this method will be a no-op. Passingnull is not allowed, and will result in an exception.

Parameters
documentListener Listener to unregister from document events. May not be null.

public void removeDocumentScrollListener (DocumentScrollListener documentScrollListener)

Removes a previously registered DocumentScrollListener. After calling this method the documentScrollListener will stop receiving scrolling events. If the listener has not been added previously, this method will be a no-op. Passingnull is not allowed, and will result in an exception.

Parameters
documentScrollListener Listener to unregister from document scroll events. May not be null.

public void removeDrawableProvider (PdfDrawableProvider drawableProvider)

Removes a previously added PdfDrawableProvider. If the provider hasn't been added previously, this method will be a no-op.

Parameters
drawableProvider PdfDrawableProvider that should be removed. Must be non-null.

public void removeOnAnnotationCreationModeChangeListener (AnnotationManager.OnAnnotationCreationModeChangeListener listener)

Remove a previously registered AnnotationManager.OnAnnotationCreationModeChangeListener. If the provider hasn't been registered previously, this method will be a no-op.

Parameters
listener Listener to unregister. Must be non-null.

public void removeOnAnnotationCreationModeSettingsChangeListener (AnnotationManager.OnAnnotationCreationModeSettingsChangeListener listener)

Remove a previously registered AnnotationManager.OnAnnotationCreationModeSettingsChangeListener. If the provider hasn't been registered previously, this method will be a no-op.

Parameters
listener Listener to unregister. Must be non-null.

public void removeOnAnnotationDeselectedListener (AnnotationManager.OnAnnotationDeselectedListener listener)

Remove a previously registered AnnotationManager.OnAnnotationDeselectedListener. If the provider hasn't been registered previously, this method will be a no-op.

Parameters
listener Listener to unregister. Must be non-null.

public void removeOnAnnotationEditingModeChangeListener (AnnotationManager.OnAnnotationEditingModeChangeListener listener)

Remove a previously registered AnnotationManager.OnAnnotationEditingModeChangeListener. If the provider hasn't been registered previously, this method will be a no-op.

Parameters
listener Listener to unregister. Must be non-null.

public void removeOnAnnotationSelectedListener (AnnotationManager.OnAnnotationSelectedListener listener)

Remove a previously registered AnnotationManager.OnAnnotationSelectedListener. If the provider hasn't been registered previously, this method will be a no-op.

Parameters
listener Listener to unregister. Must be non-null.

public void removeOnAnnotationUpdatedListener (AnnotationProvider.OnAnnotationUpdatedListener listener)

Remove a previously registered AnnotationProvider.OnAnnotationUpdatedListener. If the listener hasn't been registered previously, this method will be a no-op.

Parameters
listener Listener to unregister. Must be non-null.

public void removeOnFormElementClickedListener (FormManager.OnFormElementClickedListener listener)

Removes a previously registered FormManager.OnFormElementClickedListener. Upon calling this method the listener will no longer be notified of any changes. If the listener has not been added, this method will be a no-op. Adding null is not allowed,and will result in an exception.

Parameters
listener OnFormElementClickedListener that should be removed. Must be non-null.

public void removeOnFormElementDeselectedListener (FormManager.OnFormElementDeselectedListener listener)

Removes a previously registered FormManager.OnFormElementDeselectedListener. Upon calling this method the listener will no longer be notified of any changes. If the listener has not been added, this method will be a no-op. Adding null is not allowed,and will result in an exception.

Parameters
listener OnFormElementDeselectedListener that should be removed. Must be non-null.

public void removeOnFormElementEditingModeChangeListener (FormManager.OnFormElementEditingModeChangeListener listener)

Removes a previously registered FormManager.OnFormElementEditingModeChangeListener. Upon calling this method the listener will no longer be notified of any changes. If the listener has not been added, this method will be a no-op. Adding null is not allowed,and will result in an exception.

Parameters
listener OnFormElementEditingModeChangeListener that should be removed. Must be non-null.

public void removeOnFormElementSelectedListener (FormManager.OnFormElementSelectedListener listener)

Removes a previously registered FormManager.OnFormElementSelectedListener. Upon calling this method the listener will no longer be notified of any changes. If the listener has not been added, this method will be a no-op. Adding null is not allowed,and will result in an exception.

Parameters
listener OnFormElementSelectedListener that should be removed. Must be non-null.

public void removeOnFormElementUpdatedListener (FormManager.OnFormElementUpdatedListener listener)

Removes a previously registered FormManager.OnFormElementUpdatedListener. Upon calling this method the listener will no longer be notified of any changes. If the listener has not been added, this method will be a no-op. Adding null is not allowed,and will result in an exception.

Parameters
listener OnFormElementUpdatedListener that should be removed. Must be non-null.

public void removeOnFormElementViewUpdatedListener (FormManager.OnFormElementViewUpdatedListener listener)

Removes a previously registered FormManager.OnFormElementViewUpdatedListener. Upon calling this method the listener will no longer be notified of any changes. If the listener has not been added, this method will be a no-op. Adding null is not allowed, and will result in an exception.

Parameters
listener OnFormElementViewUpdatedListener that should be removed. Must be non-null.

public void removeOnTextSelectionChangeListener (TextSelectionManager.OnTextSelectionChangeListener listener)

Removes a TextSelectionManager.OnTextSelectionChangeListener, which gets notified when text selection changes in the document, such as different text is selected. Upon calling this method the listener will no longer be notified. If the listener has not been added, this method will be a no-op.

Parameters
listener Listener to unregister. Must be non-null.

public void removeOnTextSelectionModeChangeListener (TextSelectionManager.OnTextSelectionModeChangeListener listener)

Removes a previously added TextSelectionManager.OnTextSelectionModeChangeListener, which gets notified when entering and exiting a text selection in the document. Upon calling this method the listener will no longer be notified. If the listener has not been added, this method will be a no-op.

Parameters
listener Listener to unregister. Must be non-null.

public void save ()

Saves the file held by the document view back to it's original location. The save operation will be successful only if all document listeners return true in onDocumentSave(PdfDocument, DocumentSaveOptions) and the document was actually modified.

public void scrollTo (RectF pdfRect, int pageIndex, long duration, boolean scrollWhenVisible)

Scrolls to the given pdfRect, if necessary changing to the page. This will keep the current zoom level. If scrollWhenVisible is false this method will be a no-op if the pdfRect is already completely visible.

Parameters
pdfRect Target area.
pageIndex Page which should be scrolled to.
duration Scroll animation duration (in milliseconds).
scrollWhenVisible Whether scrolling should be performed if the target area is already completely visible, or not.

public void setAnnotationDefaultsProvider (AnnotationType annotationType, AnnotationDefaultsProvider defaultsProvider)

Configures annotation defaults provider for given annotation type. This replaces default provider.

Parameters
annotationType Type of annotation for which to set defaults provider.
defaultsProvider Defaults provider to set.

public void setBackgroundColor (int backgroundColor)

Sets the background color of the fragment. It's the background of the area behind the pages.

Parameters
backgroundColor Color to be set.

public void setCustomPdfSource (DocumentSource source)

Sets the custom source for the PDF file.

Parameters
source PDF document source.

public void setCustomPdfSources (List<DocumentSource> sources)

Sets the custom sources for the PDF file.

Parameters
sources List of PDF document sources.

public void setDocumentSigningListener (DocumentSigningListener documentSigningListener)

Sets a new DocumentSigningListener or replaces an existing one. This allows capturing of digital signing events.

If not set or set to null, a default implementation of DocumentSigningListener is used.

Parameters
documentSigningListener new document signing listener.

public void setInsets (int left, int top, int right, int bottom)

Set insets that will be used as padding for PdfFragment contents.

Parameters
left The left inset in pixels.
top The top inset in pixels.
right The right inset in pixels.
bottom The bottom inset in pixels.

public void setOnDocumentLongPressListener (OnDocumentLongPressListener listener)

Set a OnDocumentLongPressListener for long press document events. Listener registered with this method will be unregistered automatically in onDetach(). Calling this method will replace any previously set listener. You may provide null to switch to the default listener.

Parameters
listener OnDocumentLongPressListener that should be notified, or null to clear the listener.

public void setOnPreparePopupToolbarListener (OnPreparePopupToolbarListener listener)

Sets the listener that will allow you to get notified when each of the popup toolbars is prepared and ready to be displayed. This allows you to set your own items, change the appearance of the toolbar, etc.

Parameters
listener Listener to register.

public void setOverlaidAnnotationTypes (EnumSet<AnnotationType> overlayAnnotationTypes)

Sets annotation types that should be rendered as overlays.

If annotation is not rendered as overlay, it is rendered within the page image. Rendering as overlay is more performant if you frequently change annotations, but might delay page display and increase memory usage.

Following annotation types support overlay mode:

NOTE are always rendered as overlays.

Parameters
overlayAnnotationTypes Annotation types that should be rendered as overlays.

public void setOverlaidAnnotations (List<Annotation> overlayAnnotations)

Sets annotations that should be rendered as overlays. This enables overlay rendering for annotations even when their types are not enabled for overlay rendering via setOverlaidAnnotationTypes(EnumSet).

If annotation is not rendered as overlay, it is rendered within the page image. Rendering as overlay is more performant if you frequently change annotations, but might delay page display and increase memory usage.

NOTE, LINK and FILE are always rendered as overlays.

Parameters
overlayAnnotations List of annotations that should be rendered as overlays.

public void setPageIndex (int pageIndex)

Sets the pageIndex to be displayed (0 is the first one), using our default decision on animating, which is to animate the transition if the page is next/before the current page, and not animate if further away. For custom animation control , use setPageIndex(int, boolean).

This method will throw an exception if pageIndex < 0 || pageIndex >= pageCount (as returned by getPageCount()).

Parameters
pageIndex Target page which should be displayed.

public void setPageIndex (int pageIndex, boolean animated)

Sets the pageIndex to be displayed (0 is the first one). If animated is set to true, the page jump will be animated. If false, the page will be shown immediately.

This method will throw an exception if pageIndex < 0 || pageIndex >= pageCount (as returned by getPageCount()).

Parameters
pageIndex Target page which should be displayed.
animated Set to true, if a transitioning animation should be performed. Otherwise to false.

public void setPageLoadingDrawable (Drawable drawable)

Sets drawable that should be displayed instead of fragment's contents (i.e. loading throbber) until document is loaded and all visible pages are rendered.

Parameters
drawable Drawable to display while document loads and pages are being rendered, null to hide the loading drawable.

public void setPasswordView (PdfPasswordView pdfPasswordView)

Sets password view to be used for the password-protected documents.

Parameters
pdfPasswordView The password view to use.

public void setRedactionAnnotationPreviewEnabled (boolean enable)

Sets redaction annotations preview as redacted.

Parameters
enable true to show redaction annotations as redacted, false to show them as marks.

public void setScrollingEnabled (boolean enabled)

Enables/disabled the scrolling performed by the user. Enabled by default.

Parameters
enabled true to enable scrolling, false to disable it.

public void setSelectedAnnotation (Annotation annotation)

Selects a single Annotation. This will also start annotation editing mode with selected annotation being edited.

Parameters
annotation The Annotation to select

public void setSelectedAnnotations (Collection<Annotation> annotations)

Sets the currently selected Annotations. Selecting multiple annotations will not start the annotation editing mode, where selecting a single one will.

Parameters
annotations The Annotations to select.

public void setSelectedFormElement (FormElement formElement)

Sets the currently selected FormElement.

Parameters
formElement The FormElement to select.

public void setState (Bundle state)

Replace fragment state.

public void setZoomingEnabled (boolean enabled)

Enables/disabled the zooming performed by the user. Enabled by default.

Parameters
enabled true to enable zooming, false to disable it.

public void zoomBy (int focusX, int focusY, int pageIndex, float scaleFactor, long duration)

Zoom by the given scale focused on the given point in PDF coordinates.`

Parameters
focusX x-coordinate of the focus point.
focusY y-coordinate of the focus point.
pageIndex Page number.
scaleFactor Scale factor for zooming.
duration Duration of the zoom animation (milliseconds).

public void zoomTo (int focusX, int focusY, int pageIndex, float targetScale, long duration)

Zoom to the given scale focused on the given point in PDF coordinates.

Parameters
focusX x-coordinate of the focus point.
focusY y-coordinate of the focus point.
pageIndex Page number.
targetScale Final scale to zoom page to.
duration Duration of the zoom animation (milliseconds).

public void zoomTo (RectF rect, int pageIndex, long duration)

Zoom to a specific rect on the given page.

Parameters
rect Rect to zoom into.
pageIndex Page number of the target page.
duration Duration of the zoom animation in milliseconds.