java.lang.Object
   ↳ androidx.fragment.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
[Expand]
Inherited Fields
From class androidx.fragment.app.Fragment
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 addOnContentEditingContentChangeListener(ContentEditingManager.OnContentEditingContentChangeListener listener)
void addOnContentEditingModeChangeListener(ContentEditingManager.OnContentEditingModeChangeListener listener)
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 addOverlayViewProvider(OverlayViewProvider overlayViewProvider)
Adds an OverlayViewProvider for adding overlay views to this fragment.
void beginNavigation()
Notifies the navigation manager that calls to setPageIndex(int, boolean) should be added to the navigation history until endNavigation() is called.
boolean clearSelectedAnnotations()
Clears all currently selected Annotations.
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, AnnotationToolVariant annotationToolVariant)
Enter annotation creation mode on the document.
void enterAnnotationCreationMode(AnnotationTool annotationTool)
Enter annotation creation mode on the document.
void enterAnnotationEditingMode(Annotation annotation)
Enter annotation editing mode on the document.
void enterContentEditingMode()
Starts the content editing mode which allows for modifying PDF content text
void enterFormEditingMode(FormElement formElement)
void enterTextSelectionMode(int pageIndex, Range textRange)
Sets the current text selection.
void enterTextSelectionMode(int pageIndex, TextSelectionRectangles touchedTextRects)
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).
AnnotationTool getActiveAnnotationTool()
Returns the active annotation tool.
AnnotationToolVariant getActiveAnnotationToolVariant()
Returns the variant of the active annotation tool variant (if any).
AnnotationConfigurationRegistry getAnnotationConfiguration()
Returns annotation configuration registry with annotation configuration for supported annotation types and/or tools.
AnnotationPreferencesManager getAnnotationPreferences()
Returns manager for annotation preferences.
AudioModeManager getAudioModeManager()
Returns this fragment's audio mode manager instance for entering/leaving audio playback or recording modes.
int getBackgroundColor()
Gets the background color of the fragment.
PdfConfiguration getConfiguration()
Returns configuration for this PdfFragment.
ContentEditingFillColorConfiguration getContentEditingConfiguration()
Returns content editing fill color configuration

Note: This method must be called after views are created (after onCreateView(LayoutInflater, ViewGroup, Bundle)).

ContentEditingPreferencesManager getContentEditingPreferences()
Returns manager for content editing preferences.
ContentEditingState getContentEditingState()
Returns the current content editing state.
UndoManager getContentEditingUndoManager()
Returns this fragment's undo manager instance for performing undo/redo operations of content edits.
PdfDocument getDocument()
Gets the loaded document.
ImageDocument getImageDocument()
Returns the loaded image document, or null if this fragment does not hold an image 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()
Gets currently displayed document page.
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)
Gets page sibling index (usable in double page mode).
SignatureMetadata getSignatureMetadata()
Gets the currently set signature metadata.
SignatureStorage getSignatureStorage()
Gets the currently used signature storage that will be used to store signatures when they're added to the document.
Bundle getState()
Gets 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 annotation edits.
ViewProjection getViewProjection()
Returns the ViewProjection for transforming between the view coordinates and PDF coordinates.
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)
Gets zoom scale at the specified page.
boolean isDocumentInteractionEnabled()
Indicates whether interaction with the document is enabled right now.
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 isUserInterfaceEnabled()
Indicates whether UI is enabled right now.
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 onViewCreated(View view, Bundle savedInstanceState)
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 removeOnContentEditingContentChangeListener(ContentEditingManager.OnContentEditingContentChangeListener listener)
void removeOnContentEditingModeChangeListener(ContentEditingManager.OnContentEditingModeChangeListener listener)
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)
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 removeOverlayViewProvider(OverlayViewProvider overlayViewProvider)
Removes a previously added OverlayViewProvider.
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 setAnnotationOverlayRenderStrategy(AnnotationOverlayRenderStrategy overlayRenderStrategy)
Sets the annotation overlay render strategy.
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 setDocumentInteractionEnabled(boolean isDocumentInteractionEnabled)
Enables or disables interaction with the document.
void setDocumentSigningListener(DocumentSigningListener documentSigningListener)
Sets a new DocumentSigningListener or replaces an existing one.
void setInsets(int left, int top, int right, int bottom)
Sets insets that will be used as padding for PdfFragment contents.
void setOnDocumentLongPressListener(OnDocumentLongPressListener listener)
Sets 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 setSignatureMetadata(SignatureMetadata signatureMetadata)
Sets the signature metadata that will be used when digitally signing the document.
void setSignatureStorage(SignatureStorage signatureStorage)
Sets the signature storage that will be used to store signatures when they're added to the document (if saving signatures is enabled).
void setState(Bundle state)
Replace fragment state.
void setUserInterfaceEnabled(boolean isUserInterfaceEnabled)
Enables or disables the user interface.
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 androidx.fragment.app.Fragment
From class java.lang.Object
From interface android.content.ComponentCallbacks
From interface android.view.View.OnCreateContextMenuListener
From interface androidx.activity.result.ActivityResultCaller
From interface androidx.lifecycle.HasDefaultViewModelProviderFactory
From interface androidx.lifecycle.LifecycleOwner
From interface androidx.lifecycle.ViewModelStoreOwner
From interface androidx.savedstate.SavedStateRegistryOwner
From interface com.pspdfkit.annotations.actions.ActionResolver
From interface com.pspdfkit.internal.document.DocumentSaver.DocumentSaveListener
From interface com.pspdfkit.internal.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.ContentEditingManager
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 addOnContentEditingContentChangeListener (ContentEditingManager.OnContentEditingContentChangeListener listener)

public void addOnContentEditingModeChangeListener (ContentEditingManager.OnContentEditingModeChangeListener listener)

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 addOverlayViewProvider (OverlayViewProvider overlayViewProvider)

Adds an OverlayViewProvider for adding overlay views to this fragment. 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.

The OverlayViewProvider is linked with the lifecycle of the PdfFragment it is attached to, meaning that when used inside a PdfActivity you need to make sure to reattach it when the fragment changes, for example when the document changes.

Using this API requires the current license to contain the annotations component.

This API is still experimental. While it is tested, and doesn't contain any known bugs, it might be changed or removed with any minor release.

Parameters
overlayViewProvider OverlayViewProvider whose view instances should be added to the document view.
Throws
InvalidPSPDFKitLicenseException If the current license doesn't contain the annotations component.

public void beginNavigation ()

Notifies the navigation manager that calls to setPageIndex(int, boolean) should be added to the navigation history 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 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, AnnotationToolVariant annotationToolVariant)

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 an annotation creation tool selected.
annotationToolVariant Specifies the variant of the annotation tool in which to start this mode.

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. Uses default AnnotationToolVariant.

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 enterContentEditingMode ()

Starts the content editing mode which allows for modifying PDF content text

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 enterTextSelectionMode (int pageIndex, TextSelectionRectangles touchedTextRects)

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.
touchedTextRects List of rectangles (in PDF coordinates) under which text selection is to be performed
Throws
IllegalArgumentException If pageIndex is not in the page range, or if text rectangles on page don't contain any of @{code touchedTextRects}.

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 AnnotationTool getActiveAnnotationTool ()

Returns the active annotation tool.

Returns
  • Active annotation tool.

public AnnotationToolVariant getActiveAnnotationToolVariant ()

Returns the variant of the active annotation tool variant (if any).

Returns
  • Active annotation tool variant.

public AnnotationConfigurationRegistry getAnnotationConfiguration ()

Returns annotation configuration registry with annotation configuration for supported annotation types and/or tools.

Note: This method must be called after views are created (after onCreateView(LayoutInflater, ViewGroup, Bundle)).

Returns

public AnnotationPreferencesManager getAnnotationPreferences ()

Returns manager for annotation preferences.

Note: This method must be called after views are created (after onCreateView(LayoutInflater, ViewGroup, Bundle)).

Returns
  • The annotation preferences manager of this fragment.

public AudioModeManager getAudioModeManager ()

Returns this fragment's audio mode manager instance for entering/leaving audio playback or recording modes.

Returns

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 ContentEditingFillColorConfiguration getContentEditingConfiguration ()

Returns content editing fill color configuration

Note: This method must be called after views are created (after onCreateView(LayoutInflater, ViewGroup, Bundle)).

Returns

public ContentEditingPreferencesManager getContentEditingPreferences ()

Returns manager for content editing preferences.

Note: This method must be called after views are created (after onCreateView(LayoutInflater, ViewGroup, Bundle)).

Returns
  • The content editing preferences manager of this fragment.

public ContentEditingState getContentEditingState ()

Returns the current content editing state.

Returns
  • Current content editing data, or null if content editing is not active.

public UndoManager getContentEditingUndoManager ()

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

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

public PdfDocument getDocument ()

Gets the loaded document.

Returns
  • Document loaded into the fragment.

public ImageDocument getImageDocument ()

Returns the loaded image document, or null if this fragment does not hold an image document.

Returns

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 ()

Gets currently displayed document page.

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

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)

Gets 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 SignatureMetadata getSignatureMetadata ()

Gets the currently set signature metadata.

Returns
  • The currently used signature metadata.

public SignatureStorage getSignatureStorage ()

Gets the currently used signature storage that will be used to store signatures when they're added to the document.

If Electronic Signatures are enabled in your license, this property defaults to null, which means signatures can't be saved. To enable simple on-device signature storage, set this to an instance of SignatureStorage.

If Annotations were enabled in your license before the introduction of the Electronic Signatures component, this defaults to our DatabaseSignatureStorage implementation.

To remove the UI option to choose whether or not to save signatures and force them to be saved, change the `signatureSavingStrategy` in your PdfConfiguration or the used SignatureOptions.

Returns
  • Currently used signature storage.

public Bundle getState ()

Gets 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 annotation edits.

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

public ViewProjection getViewProjection ()

Returns the ViewProjection for transforming between the view coordinates and PDF coordinates.

Returns
  • ViewProjection for transforming between the view coordinates and PDF coordinates.

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)

Gets 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 isDocumentInteractionEnabled ()

Indicates whether interaction with the document is enabled right now.

Returns
  • true when the user can interact with the document, false otherwise.

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 isUserInterfaceEnabled ()

Indicates whether UI is enabled right now. UI is disabled when document is being saved/loaded, or when manually disabled.

Returns
  • true when UI is enabled right now.

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 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. This has to be called on the main thread.

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. Page index is 0-based.

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 if the annotation is being created.
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 onViewCreated (View view, Bundle savedInstanceState)

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 removeOnContentEditingContentChangeListener (ContentEditingManager.OnContentEditingContentChangeListener listener)

public void removeOnContentEditingModeChangeListener (ContentEditingManager.OnContentEditingModeChangeListener listener)

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 removeOverlayViewProvider (OverlayViewProvider overlayViewProvider)

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

Using this API requires the current license to contain the annotations component.

This API is still experimental. While it is tested, and doesn't contain any known bugs, it might be changed or removed with any minor release.

Parameters
overlayViewProvider OverlayViewProvider that should be removed. Must be non-null.
Throws
InvalidPSPDFKitLicenseException If the current license doesn't contain the annotations component.

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 setAnnotationOverlayRenderStrategy (AnnotationOverlayRenderStrategy overlayRenderStrategy)

Sets the annotation overlay render strategy. This strategy defines how annotations that are displayed in overlay mode (i.e. views which are rendered as views inside the activities view hierarchy) should be rendered. By default, PSPDFKit uses PLATFORM_RENDERING for all annotations. You can override this behavior by setting a custom strategy using this method. For more information about the available render strategies please see AnnotationOverlayRenderStrategy.

Note: Render strategy is used whenever annotation is extracted to overlay - i.e. after changing set of overlaid annotations (or types), creating new annotations or when loading page after opening the document or scrolling to a new page that is not yet cached (PSPDFKit instantiates around 5 pages around the currently visible pages to achieve smooth scrolling). Note that strategy changes are not applied until above events occur.

Parameters
overlayRenderStrategy Overlay annotations render strategy, null to use the default strategy.

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 setDocumentInteractionEnabled (boolean isDocumentInteractionEnabled)

Enables or disables interaction with the document. When the interaction is disabled you can no longer scroll or zoom the document in any way, any other UI like the thumbnail bar is still enabled.

Parameters
isDocumentInteractionEnabled true to enable interacting with the document, false to disable it.

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)

Sets 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)

Sets 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 performs better 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 setSignatureMetadata (SignatureMetadata signatureMetadata)

Sets the signature metadata that will be used when digitally signing the document.

Parameters
signatureMetadata The signature metadata that will be used when digitally signing the document, or null to not add additional metadata.

public void setSignatureStorage (SignatureStorage signatureStorage)

Sets the signature storage that will be used to store signatures when they're added to the document (if saving signatures is enabled).

Parameters
signatureStorage Signature storage to use when saving signatures, or null to use the default one.

public void setState (Bundle state)

Replace fragment state.

public void setUserInterfaceEnabled (boolean isUserInterfaceEnabled)

Enables or disables the user interface. When the user interface is disabled all temporary UI elements (navigation buttons, readaction UI) are hidden, and all user interaction is disabled (no scrolling, no clicking on the thumbnail bar, no annotation editing).

Parameters
isUserInterfaceEnabled true to enable the UI, false to disable the UI.

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.