Class PdfFragment
-
- All Implemented Interfaces:
-
android.content.ComponentCallbacks
,android.view.View.OnCreateContextMenuListener
,androidx.activity.result.ActivityResultCaller
,androidx.lifecycle.HasDefaultViewModelProviderFactory
,androidx.lifecycle.LifecycleOwner
,androidx.lifecycle.ViewModelStoreOwner
,androidx.savedstate.SavedStateRegistryOwner
,com.pspdfkit.annotations.actions.ActionResolver
,com.pspdfkit.internal.annotations.clipboard.CopyPasteManagerClient
,com.pspdfkit.internal.document.DocumentSaver.DocumentSaveListener
,com.pspdfkit.internal.views.document.SpecialModeManager
,com.pspdfkit.listeners.DocumentListener
,com.pspdfkit.listeners.scrolling.DocumentScrollListener
,com.pspdfkit.ui.drawable.PdfDrawableManager
,com.pspdfkit.ui.navigation.PageNavigator
,com.pspdfkit.ui.special_mode.manager.AnnotationManager
,com.pspdfkit.ui.special_mode.manager.AnnotationManager.OnAnnotationDeselectedListener
,com.pspdfkit.ui.special_mode.manager.AnnotationManager.OnAnnotationSelectedListener
,com.pspdfkit.ui.special_mode.manager.ContentEditingManager
,com.pspdfkit.ui.special_mode.manager.FormManager
,com.pspdfkit.ui.special_mode.manager.FormManager.OnFormElementDeselectedListener
,com.pspdfkit.ui.special_mode.manager.FormManager.OnFormElementSelectedListener
,com.pspdfkit.ui.special_mode.manager.TextSelectionManager
public class PdfFragment extends Fragment implements DocumentListener, DocumentScrollListener, PdfDrawableManager, AnnotationManager, ContentEditingManager, FormManager, TextSelectionManager, SpecialModeManager, PageNavigator, AnnotationManager.OnAnnotationSelectedListener, AnnotationManager.OnAnnotationDeselectedListener, ActionResolver, FormManager.OnFormElementSelectedListener, FormManager.OnFormElementDeselectedListener, DocumentSaver.DocumentSaveListener, CopyPasteManagerClient
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.
-
-
Field Summary
Fields Modifier and Type Field Description public final static String
PARAM_CONFIGURATION
public final static String
PARAM_SOURCES
public final static String
PARAM_IMAGE_DOCUMENT_SOURCE
public final static String
DOCUMENTSTORE_KEY_LAST_VIEWED_PAGE_INDEX
public final static float
DEFAULT_ZOOM
public final static float
MIN_ZOOM
public final static float
MAX_ZOOM
public final static int
DOCUMENT_VIEW_ID
public PdfConfiguration
configuration
public ImageDocument
imageDocument
public SignatureStorage
signatureStorage
public MeasurementValueConfigurationEditor
measurementValueConfigurationEditor
public final NavigationBackStack<NavigationBackStack.NavigationItem<Integer>>
navigationHistory
public boolean
isUserInterfaceEnabled
public boolean
isDocumentInteractionEnabled
-
Constructor Summary
Constructors Constructor Description PdfFragment()
This constructor is for internal usage only.
-
Method Summary
Modifier and Type Method Description PdfConfiguration
getConfiguration()
Returns configuration for this PdfFragment. ImageDocument
getImageDocument()
Returns the loaded image document, or null
if this fragment does not hold an image document.SignatureStorage
getSignatureStorage()
Gets the currently used signature storage that will be used to store signatures when they're added to the document. void
setSignatureStorage(@Nullable() 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). MeasurementValueConfigurationEditor
getMeasurementValueConfigurationEditor()
Get an editor object that allows you to add/delete/modify measurement scales MeasurementValueConfiguration NavigationBackStack<NavigationBackStack.NavigationItem<Integer>>
getNavigationHistory()
Returns the navigation history owned by this manager. boolean
isUserInterfaceEnabled()
Indicates whether UI is enabled right now. void
setUserInterfaceEnabled(boolean isUserInterfaceEnabled)
Enables or disables the user interface. boolean
isDocumentInteractionEnabled()
Indicates whether interaction with the document is enabled right now. void
setDocumentInteractionEnabled(boolean isDocumentInteractionEnabled)
Enables or disables interaction with the document. static PdfFragment
newInstance(@NonNull() Uri documentUri, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document. static PdfFragment
newInstance(@NonNull() Uri documentUri, @Nullable() String password, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document. static PdfFragment
newInstance(@NonNull() Uri documentUri, @Nullable() String password, @Nullable() String contentSignature, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document. static PdfFragment
newInstance(@NonNull() List<Uri> documentUris, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display passed list of PDF documents as a single compound document. static PdfFragment
newInstance(@NonNull() List<Uri> documentUris, @Nullable() List<String> documentPasswords, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display passed list of PDF documents as a single compound document. static PdfFragment
newInstance(@NonNull() List<Uri> documentUris, @Nullable() List<String> documentPasswords, @Nullable() List<String> documentContentSignatures, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display passed list of PDF documents as a single compound document. static PdfFragment
newImageInstance(@NonNull() Uri documentUri, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display a converted PDF document from a supported image format. static PdfFragment
newImageInstance(@NonNull() DataProvider source, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display a converted PDF document from a supported image format. static PdfFragment
newImageInstance(@NonNull() DocumentSource source, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display a converted PDF document from a supported image format. static PdfFragment
newInstance(@NonNull() DataProvider source, @Nullable() String password, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document from a custom data source. static PdfFragment
newInstance(@NonNull() DataProvider source, @Nullable() String password, @Nullable() String contentSignature, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document from a custom data source static PdfFragment
newInstanceFromSources(@NonNull() List<DataProvider> sources, @NonNull() 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(@NonNull() List<DataProvider> sources, @Nullable() List<String> passwords, @NonNull() 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(@NonNull() List<DataProvider> sources, @Nullable() List<String> passwords, @Nullable() List<String> contentSignatures, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document from a custom data source as a compound document. static PdfFragment
newInstance(@NonNull() PdfDocument document, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document from an already opened instance. static PdfFragment
newInstance(@NonNull() PdfFragment fragment, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document from an PdfFragment. static PdfFragment
newInstanceFromDocumentSources(@NonNull() List<DocumentSource> sources, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document from the given DocumentSources. void
setSelectedMeasurementValueConfiguration(@NonNull() MeasurementValueConfiguration configuration)
For measurement tools, you can set and select whichever MeasurementValueConfiguration you want using this API. InternalPdfFragmentApi
getInternal()
Returns the InternalPdfFragmentApi. Bundle
getState()
Gets current state of the fragment. void
setState(@NonNull() Bundle state)
Replace fragment state. void
onAttach(@NonNull() Context context)
void
onCreate(Bundle savedInstanceState)
View
onCreateView(@NonNull() LayoutInflater inflater, @Nullable() ViewGroup container, @Nullable() Bundle savedInstanceState)
void
onViewCreated(@NonNull() View view, @Nullable() Bundle savedInstanceState)
void
onResume()
void
refreshPages()
Re initialises DocumentView if total number of visible pages are 0. void
onSaveInstanceState(@NonNull() Bundle outState)
Called by the activity if it requires the fragment to save its state. void
onConfigurationChanged(@NonNull() Configuration newConfig)
void
onStop()
void
onLowMemory()
void
onDestroyView()
void
onDestroy()
void
onDetach()
boolean
save()
Saves the file held by the document view back to it's original location. void
saveAsync()
Saves the file held by the document view back to it's original location. PdfDocument
getDocument()
Gets the loaded document. void
setSelectedAnnotation(@NonNull() Annotation annotation)
Selects a single Annotation. List<Annotation>
getSelectedAnnotations()
Returns a list of currently selected annotations, or an empty list if no annotations were selected. void
setSelectedAnnotations(@NonNull() Collection<out Annotation> annotations)
Sets the currently selected Annotations. boolean
clearSelectedAnnotations()
Clears all currently selected Annotations. void
addAnnotationToPage(@NonNull() Annotation annotation, boolean selectImmediately)
Adds annotation to page asynchronously, refreshing rendering in all UI components. void
addAnnotationToPage(@NonNull() Annotation annotation, boolean selectImmediately, @Nullable() Runnable completeAction)
Adds annotation to page asynchronously, refreshing rendering in all UI components. FormElement
getSelectedFormElement()
Returns currently selected form element. void
setSelectedFormElement(@NonNull() FormElement formElement)
Sets the currently selected FormElement. int
getPageIndex()
Gets currently displayed document page. int
getPageCount()
Gets number of pages in the document. int
getSiblingPageIndex(@IntRange(from = "-1") int pageIndex)
Gets page sibling index (usable in double page mode). void
setPageIndex(@IntRange(from = 0) 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(@IntRange(from = 0) int pageIndex, boolean animated)
Sets the pageIndex
to be displayed (0 is the first one).void
zoomBy(int focusX, int focusY, @IntRange(from = 0) 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, @IntRange(from = 0) int pageIndex, float targetScale, long duration)
Zoom to the given scale focused on the given point in PDF coordinates. void
zoomTo(RectF rect, @IntRange(from = 0) int pageIndex, long duration)
Zoom to a specific rect on the given page. float
getZoomScale(@IntRange(from = 0) int pageIndex)
Gets zoom scale at the specified page. void
scrollTo(@NonNull() RectF pdfRect, @IntRange(from = 0) int pageIndex, long duration, boolean scrollWhenVisible)
Scrolls to the given pdfRect
, if necessary changing to thepage
.void
setCustomPdfSource(@NonNull() DocumentSource source)
Sets the custom source for the PDF file. void
setCustomPdfSources(@NonNull() List<DocumentSource> sources)
Sets the custom sources for the PDF file. int
getBackgroundColor()
Gets the background color of the fragment. void
setBackgroundColor(int backgroundColor)
Sets the background color of the fragment. boolean
isScrollingEnabled()
Indicates whether the scrolling is enabled, or not. void
setScrollingEnabled(boolean enabled)
Enables/disabled the scrolling performed by the user. boolean
isZoomingEnabled()
Indicates whether the zooming is enabled, or not. void
setZoomingEnabled(boolean enabled)
Enables/disabled the zooming performed by the user. boolean
isImageDocument()
Indicates whether the displayed document is an image or not. ViewProjection
getViewProjection()
Returns the ViewProjection for transforming between the view coordinates and PDF coordinates. boolean
getVisiblePdfRect(@NonNull() RectF targetRect, @IntRange(from = 0) int pageIndex)
Sets targetRect
to contain the visible PDF rect of the givenpageIndex
.List<Integer>
getVisiblePages()
Fetch the list of pages currently visible on the screen. void
setOnPreparePopupToolbarListener(@Nullable() 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
addDocumentListener(@NonNull() DocumentListener documentListener)
Adds a DocumentListener for listening to document events. void
removeDocumentListener(@NonNull() DocumentListener documentListener)
Removes a previously registered DocumentListener. void
addDocumentScrollListener(@NonNull() DocumentScrollListener documentScrollListener)
Adds a DocumentScrollListener for listening to scrolling events on the document. void
removeDocumentScrollListener(@NonNull() DocumentScrollListener documentScrollListener)
Removes a previously registered DocumentScrollListener. void
notifyAnnotationHasChanged(@NonNull() Annotation annotation)
Notifies this fragment that the passed annotation has changed and that all the views displaying it should be updated. void
notifyAnnotationsHaveChanged(@NonNull() List<out Annotation> annotations)
Notifies this fragment that the passed annotations have changed and that all the views displaying it should be updated. void
beginNavigation()
Notifies the navigation manager that calls to setPageIndex should be added to the navigation history until endNavigation is called. void
endNavigation()
Commits the page changes to the navigation history dropping everything but the very last one. void
executeAction(@NonNull() Action action)
Executes the given PDF action
on the currently loaded document.void
executeAction(@NonNull() Action action, @Nullable() ActionSender actionSender)
Executes the given PDF action
on the currently loaded document.void
addDocumentActionListener(@NonNull() DocumentActionListener listener)
Adds a DocumentActionListener that can handle actions bound to PDF objects. void
removeDocumentActionListener(@NonNull() DocumentActionListener listener)
Removes a previously added DocumentActionListener that can handle actions bound to PDF objects. void
onDocumentLoaded(@NonNull() PdfDocument document)
Called when document is successfully loaded and the document view has been laid out. String
getAnnotationCreator()
OnEditRecordedListener
getRecordedListener()
void
onAnnotationsCopied(@NonNull() List<out Annotation> annotations)
The following listener methods are called after successful operation. void
onAnnotationsPasted(@NonNull() List<out Annotation> annotations)
void
onAnnotationsCut(@NonNull() List<out Annotation> annotations)
void
onDocumentLoadFailed(@NonNull() Throwable exception)
Called if document loading has failed. boolean
onDocumentSave(@NonNull() PdfDocument document, @NonNull() DocumentSaveOptions saveOptions)
Called before document will be saved. void
onDocumentSaved(@NonNull() PdfDocument document)
Called after the document has been saved. void
onDocumentSaveFailed(@NonNull() PdfDocument document, @NonNull() Throwable exception)
Called if document saving has failed. void
onDocumentSaveCancelled(@NonNull() PdfDocument document)
Called if document saving has been cancelled. boolean
onPageClick(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex, @Nullable() MotionEvent event, @Nullable() PointF pagePosition, @Nullable() Annotation clickedAnnotation)
Called when user taps / clicks on the page. boolean
onDocumentClick()
Called when the user taps / clicks on the document, not the page itself but on the side (if visible). void
onPageChanged(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex)
Called when user scrolled to a new page. void
onDocumentZoomed(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex, float scaleFactor)
Called when a user zooms a document. void
onPageUpdated(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex)
Called when content of page with pageIndex has changed (for example due to annotation or form field being updated). PdfPasswordView
getPasswordView()
Returns currently set password view for the fragment. void
setPasswordView(@NonNull() PdfPasswordView pdfPasswordView)
Sets password view to be used for the password-protected documents. AnnotationConfigurationRegistry
getAnnotationConfiguration()
Returns annotation configuration registry with annotation configuration for supported annotation types and/or tools. ContentEditingFillColorConfiguration
getContentEditingConfiguration()
Returns content editing fill color configuration Note: This method must be called after views are created (after onCreateView). AnnotationPreferencesManager
getAnnotationPreferences()
Returns manager for annotation preferences. ContentEditingPreferencesManager
getContentEditingPreferences()
Returns manager for content editing preferences. void
addDrawableProvider(@NonNull() PdfDrawableProvider drawableProvider)
Adds a PdfDrawableProvider to be managed by this object. void
removeDrawableProvider(@NonNull() PdfDrawableProvider drawableProvider)
Removes a previously added PdfDrawableProvider. void
addOverlayViewProvider(@NonNull() OverlayViewProvider overlayViewProvider)
Adds an OverlayViewProvider for adding overlay views to this fragment. void
removeOverlayViewProvider(@NonNull() OverlayViewProvider overlayViewProvider)
Removes a previously added OverlayViewProvider. void
addOnAnnotationSelectedListener(@NonNull() AnnotationManager.OnAnnotationSelectedListener listener)
Register a OnAnnotationSelectedListener to get notified when annotation gets selected. void
removeOnAnnotationSelectedListener(@NonNull() AnnotationManager.OnAnnotationSelectedListener listener)
Remove a previously registered OnAnnotationSelectedListener. void
addOnAnnotationDeselectedListener(@NonNull() AnnotationManager.OnAnnotationDeselectedListener listener)
Register a OnAnnotationDeselectedListener to get notified when annotation gets deselected. void
removeOnAnnotationDeselectedListener(@NonNull() AnnotationManager.OnAnnotationDeselectedListener listener)
Remove a previously registered OnAnnotationDeselectedListener. void
addOnAnnotationUpdatedListener(@NonNull() AnnotationProvider.OnAnnotationUpdatedListener listener)
Register a AnnotationProvider.OnAnnotationUpdatedListener to get notified when annotation gets updated. void
removeOnAnnotationUpdatedListener(@NonNull() AnnotationProvider.OnAnnotationUpdatedListener listener)
Remove a previously registered AnnotationProvider.OnAnnotationUpdatedListener. void
addOnAnnotationCreationModeChangeListener(@NonNull() AnnotationManager.OnAnnotationCreationModeChangeListener listener)
Register a OnAnnotationCreationModeChangeListener to get notified when annotation creation mode gets updated. void
removeOnAnnotationCreationModeChangeListener(@NonNull() AnnotationManager.OnAnnotationCreationModeChangeListener listener)
Remove a previously registered OnAnnotationCreationModeChangeListener. void
addOnAnnotationCreationModeSettingsChangeListener(@NonNull() AnnotationManager.OnAnnotationCreationModeSettingsChangeListener listener)
Register a OnAnnotationCreationModeSettingsChangeListener to get notified when annotation creation settings get updated. void
removeOnAnnotationCreationModeSettingsChangeListener(@NonNull() AnnotationManager.OnAnnotationCreationModeSettingsChangeListener listener)
Remove a previously registered OnAnnotationCreationModeSettingsChangeListener. void
addOnAnnotationEditingModeChangeListener(@NonNull() AnnotationManager.OnAnnotationEditingModeChangeListener listener)
Register a OnAnnotationEditingModeChangeListener to get notified when annotation editing mode gets updated. void
removeOnAnnotationEditingModeChangeListener(@NonNull() AnnotationManager.OnAnnotationEditingModeChangeListener listener)
Remove a previously registered OnAnnotationEditingModeChangeListener. void
addOnContentEditingModeChangeListener(@NonNull() ContentEditingManager.OnContentEditingModeChangeListener listener)
void
removeOnContentEditingModeChangeListener(@NonNull() ContentEditingManager.OnContentEditingModeChangeListener listener)
void
addOnContentEditingContentChangeListener(@NonNull() ContentEditingManager.OnContentEditingContentChangeListener listener)
void
removeOnContentEditingContentChangeListener(@NonNull() ContentEditingManager.OnContentEditingContentChangeListener listener)
void
setInsets(@IntRange(from = 0) int left, @IntRange(from = 0) int top, @IntRange(from = 0) int right, @IntRange(from = 0) int bottom)
Sets insets that will be used as padding for PdfFragment contents. void
addInsets(int leftOffset, int topOffset, int rightOffset, int bottomOffset)
Offset PdfFragment insets by specified amount. void
enterContentEditingMode()
Starts the content editing mode which allows for modifying PDF content text void
enterAnnotationCreationMode()
Starts the annotation creation mode with the last used annotation tool as the selected one. void
enterAnnotationCreationMode(@NonNull() AnnotationTool annotationTool)
Enter annotation creation mode on the document. void
enterAnnotationCreationMode(@NonNull() AnnotationTool annotationTool, @NonNull() AnnotationToolVariant annotationToolVariant)
Enter annotation creation mode on the document. void
enterTextSelectionMode(@IntRange(from = 0) int pageIndex, @NonNull() Range textRange)
Sets the current text selection. void
enterTextSelectionMode(int pageIndex, @NonNull() TextSelectionRectangles touchedTextRects)
Sets the current text selection. void
enterAnnotationEditingMode(@NonNull() List<Annotation> annotations)
Enter annotation editing mode on the document. void
enterAnnotationEditingMode(@NonNull() Annotation annotation)
Enter annotation editing mode on the document. void
enterFormEditingMode(@NonNull() FormElement formElement)
Enter form editing mode on the document. void
exitCurrentlyActiveMode()
Exit any currently active mode on the document (annotation creation, annotation editing, text selection). boolean
isInSpecialMode()
Returns true
if any of the special modes is active.AnnotationTool
getActiveAnnotationTool()
Returns the active annotation tool. AnnotationToolVariant
getActiveAnnotationToolVariant()
Returns the variant of the active annotation tool variant (if any). TextSelection
getTextSelection()
Returns the current text selection. ContentEditingState
getContentEditingState()
Returns the current content editing state. void
addOnTextSelectionModeChangeListener(@NonNull() TextSelectionManager.OnTextSelectionModeChangeListener listener)
Adds a OnTextSelectionModeChangeListener, which gets notified when entering and exiting a text selection in the document. void
removeOnTextSelectionModeChangeListener(@NonNull() TextSelectionManager.OnTextSelectionModeChangeListener listener)
Removes a previously added OnTextSelectionModeChangeListener, which gets notified when entering and exiting a text selection in the document. void
addOnTextSelectionChangeListener(@NonNull() TextSelectionManager.OnTextSelectionChangeListener listener)
Adds a OnTextSelectionChangeListener, which gets notified when text selection changes in the document, such as different text is selected. void
removeOnTextSelectionChangeListener(@NonNull() TextSelectionManager.OnTextSelectionChangeListener listener)
Removes a OnTextSelectionChangeListener, which gets notified when text selection changes in the document, such as different text is selected. void
onAnnotationDeselected(@NonNull() Annotation annotation, boolean reselected)
Called when annotation gets deselected. boolean
onPrepareAnnotationSelection(@NonNull() AnnotationSelectionController controller, @NonNull() Annotation annotation, boolean annotationCreated)
Called immediately before annotation is going to be selected. void
onAnnotationSelected(@NonNull() Annotation annotation, boolean annotationCreated)
Called when annotation gets selected. void
onAnnotationSelectionFinished(@NonNull() List<Annotation> annotations, boolean annotationCreated)
Called when annotation gets selected. void
onFormElementSelected(@NonNull() FormElement formElement)
Called when form element gets selected. void
onFormElementDeselected(@NonNull() FormElement formElement, boolean reselected)
Called when form element gets deselected. void
onScrollStateChanged(@NonNull() ScrollState state)
Called whenever the current scroll state of the document view has changed. void
onDocumentScrolled(int currX, int currY, int maxX, int maxY, int extendX, int extendY)
Called whenever the document in the fragment scrolled. void
notifyLayoutChanged()
Notifies layout has changed and properly updates its internal state and views. void
addOnFormElementSelectedListener(@NonNull() FormManager.OnFormElementSelectedListener listener)
Adds a OnFormElementSelectedListener to get notified when form element gets selected. void
removeOnFormElementSelectedListener(@NonNull() FormManager.OnFormElementSelectedListener listener)
Removes a previously registered OnFormElementSelectedListener. void
addOnFormElementDeselectedListener(@NonNull() FormManager.OnFormElementDeselectedListener listener)
Adds a OnFormElementDeselectedListener to get notified when form element gets deselected. void
removeOnFormElementDeselectedListener(@NonNull() FormManager.OnFormElementDeselectedListener listener)
Removes a previously registered OnFormElementDeselectedListener. void
addOnFormElementUpdatedListener(@NonNull() FormManager.OnFormElementUpdatedListener listener)
Adds a OnFormElementUpdatedListener to get notified when form element gets updated. void
removeOnFormElementUpdatedListener(@NonNull() FormManager.OnFormElementUpdatedListener listener)
Removes a previously registered OnFormElementUpdatedListener. void
addOnFormElementEditingModeChangeListener(@NonNull() FormManager.OnFormElementEditingModeChangeListener listener)
Adds a OnFormElementEditingModeChangeListener to get notified when form element editing mode gets updated. void
removeOnFormElementEditingModeChangeListener(@NonNull() FormManager.OnFormElementEditingModeChangeListener listener)
Removes a previously registered OnFormElementEditingModeChangeListener. void
addOnFormElementClickedListener(@NonNull() FormManager.OnFormElementClickedListener listener)
Adds a OnFormElementClickedListener to get notified when form element has been clicked. void
removeOnFormElementClickedListener(@NonNull() FormManager.OnFormElementClickedListener listener)
Removes a previously registered OnFormElementClickedListener. void
addOnFormElementViewUpdatedListener(@NonNull() FormManager.OnFormElementViewUpdatedListener listener)
Adds a OnFormElementViewUpdatedListener to get notified about form element view update events. void
removeOnFormElementViewUpdatedListener(@NonNull() FormManager.OnFormElementViewUpdatedListener listener)
Removes a previously registered OnFormElementViewUpdatedListener. UndoManager
getUndoManager()
Returns this fragment's undo manager instance for performing undo/redo operations of annotation edits. UndoManager
getContentEditingUndoManager()
Returns this fragment's undo manager instance for performing undo/redo operations of content edits. AudioModeManager
getAudioModeManager()
Returns this fragment's audio mode manager instance for entering/leaving audio playback or recording modes. void
setOverlaidAnnotationTypes(@NonNull() EnumSet<AnnotationType> overlayAnnotationTypes)
Sets annotation types that should be rendered as overlays. EnumSet<AnnotationType>
getOverlaidAnnotationTypes()
Gets annotation types that should be rendered as overlays. void
setOverlaidAnnotations(@NonNull() List<Annotation> overlayAnnotations)
Sets annotations that should be rendered as overlays. List<Annotation>
getOverlaidAnnotations()
Gets annotations that should be rendered as overlays. void
setAnnotationOverlayRenderStrategy(@Nullable() AnnotationOverlayRenderStrategy overlayRenderStrategy)
Sets the annotation overlay render strategy. void
setPageLoadingDrawable(@Nullable() Drawable drawable)
Sets drawable that should be displayed instead of fragment's contents (i.e. boolean
isRedactionAnnotationPreviewEnabled()
Returns redaction annotation preview mode, false
by default.void
addAnnotationViewsListener(@NonNull() AnnotationViewsListener listener)
Adds an AnnotationViewsListener to the list of listeners that will be notified when the internal views factory creates an EditText widget for editing a freetext annotation void
removeAnnotationViewsListener(@NonNull() AnnotationViewsListener listener)
Removes a listener from the list of AnnotationViewsListeners. void
setOnDocumentLongPressListener(@Nullable() OnDocumentLongPressListener listener)
Sets a OnDocumentLongPressListener for long press document events. void
setRedactionAnnotationPreviewEnabled(boolean enable)
Sets redaction annotations preview as redacted. -
-
Method Detail
-
getConfiguration
@NonNull() PdfConfiguration getConfiguration()
Returns configuration for this PdfFragment.
- Returns:
A page rendering configuration for this fragment.
-
getImageDocument
@Nullable() ImageDocument getImageDocument()
Returns the loaded image document, or
null
if this fragment does not hold an image document.- Returns:
ImageDocument instance or
null
if no image document is loaded.
-
getSignatureStorage
@Nullable() 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
- Returns:
Currently used signature storage.
-
setSignatureStorage
void setSignatureStorage(@Nullable() 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, ornull
to use the default one.
-
getMeasurementValueConfigurationEditor
@Nullable() MeasurementValueConfigurationEditor getMeasurementValueConfigurationEditor()
Get an editor object that allows you to add/delete/modify measurement scales MeasurementValueConfiguration
- Returns:
a MeasurementValueConfigurationEditor instance. Be aware that this function returns
null
until a PDFDocument is assigned to the fragment.
-
getNavigationHistory
@NonNull() NavigationBackStack<NavigationBackStack.NavigationItem<Integer>> getNavigationHistory()
Returns the navigation history owned by this manager.
- Returns:
NavigationBackStack containing the entire navigation history.
-
isUserInterfaceEnabled
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.
-
setUserInterfaceEnabled
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.
-
isDocumentInteractionEnabled
boolean isDocumentInteractionEnabled()
Indicates whether interaction with the document is enabled right now.
- Returns:
true
when the user can interact with the document,false
otherwise.
-
setDocumentInteractionEnabled
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.
-
newInstance
@NonNull() static PdfFragment newInstance(@NonNull() Uri documentUri, @NonNull() 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 .- Returns:
New instance of fragment that can be attached to view hierarchy.
-
newInstance
@NonNull() static PdfFragment newInstance(@NonNull() Uri documentUri, @Nullable() String password, @NonNull() 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 benull
.configuration
- Configuration for PDF display generated with .- Returns:
New instance of fragment that can be attached to view hierarchy.
-
newInstance
@NonNull() static PdfFragment newInstance(@NonNull() Uri documentUri, @Nullable() String password, @Nullable() String contentSignature, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document.
- Parameters:
documentUri
- pointing to the document to openpassword
- Document password, can benull
.contentSignature
- Content signature, can benull
.configuration
- Configuration for PDF display generated with .- Returns:
New instance of fragment that can be attached to view hierarchy.
-
newInstance
@NonNull() static PdfFragment newInstance(@NonNull() List<Uri> documentUris, @NonNull() 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 .- Returns:
New instance of fragment that can be attached to view hierarchy.
-
newInstance
@NonNull() static PdfFragment newInstance(@NonNull() List<Uri> documentUris, @Nullable() List<String> documentPasswords, @NonNull() 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 .- Returns:
New instance of fragment that can be attached to view hierarchy.
-
newInstance
@NonNull() static PdfFragment newInstance(@NonNull() List<Uri> documentUris, @Nullable() List<String> documentPasswords, @Nullable() List<String> documentContentSignatures, @NonNull() 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 .- Returns:
New instance of Fragment that can be attached to view hierarchy.
-
newImageInstance
@NonNull() static PdfFragment newImageInstance(@NonNull() Uri documentUri, @NonNull() 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 , or getDefaultImageDocumentConfiguration.- Returns:
New instance of fragment that can be attached to view hierarchy.
-
newImageInstance
@NonNull() static PdfFragment newImageInstance(@NonNull() DataProvider source, @NonNull() 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.configuration
- Configuration for the image document to display generated with , or getDefaultImageDocumentConfiguration.- Returns:
New instance of fragment that can be attached to view hierarchy.
-
newImageInstance
@NonNull() static PdfFragment newImageInstance(@NonNull() DocumentSource source, @NonNull() 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 fromconfiguration
- Configuration for the image document to display generated with , or getDefaultImageDocumentConfiguration.- Returns:
New instance of fragment that can be attached to view hierarchy.
-
newInstance
@NonNull() static PdfFragment newInstance(@NonNull() DataProvider source, @Nullable() String password, @NonNull() 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.password
- Document password, can benull
.configuration
- Configuration for PDF display generated with .- Returns:
New instance of fragment that can be attached to view hierarchy.
-
newInstance
@NonNull() static PdfFragment newInstance(@NonNull() DataProvider source, @Nullable() String password, @Nullable() String contentSignature, @NonNull() 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.password
- Document password, can benull
.contentSignature
- Content signature, can benull
.configuration
- Configuration for PDF display generated with .- Returns:
New instance of fragment that can be attached to view hierarchy.
-
newInstanceFromSources
@NonNull() static PdfFragment newInstanceFromSources(@NonNull() List<DataProvider> sources, @NonNull() 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.configuration
- Configuration for PDF display generated with .- Returns:
New instance of fragment that can be attached to view hierarchy.
-
newInstanceFromSources
@NonNull() static PdfFragment newInstanceFromSources(@NonNull() List<DataProvider> sources, @Nullable() List<String> passwords, @NonNull() 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.passwords
- Document password, can benull
.configuration
- Configuration for PDF display generated with .- Returns:
New instance of fragment that can be attached to view hierarchy.
-
newInstanceFromSources
@NonNull() static PdfFragment newInstanceFromSources(@NonNull() List<DataProvider> sources, @Nullable() List<String> passwords, @Nullable() List<String> contentSignatures, @NonNull() 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.passwords
- Document password, can benull
.contentSignatures
- Content signature, can benull
.configuration
- Configuration for PDF display generated with .- Returns:
New instance of fragment that can be attached to view hierarchy.
-
newInstance
static PdfFragment newInstance(@NonNull() PdfDocument document, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document from an already opened instance. This will not reload the document.
- Parameters:
document
- An already opened instance of a PdfDocument object.configuration
- Configuration for PDF display generated with .- Returns:
New instance of fragment that can be attached to view hierarchy.
-
newInstance
static PdfFragment newInstance(@NonNull() PdfFragment fragment, @NonNull() 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 .- Returns:
New instance of fragment that can be attached to view hierarchy.
-
newInstanceFromDocumentSources
@NonNull() static PdfFragment newInstanceFromDocumentSources(@NonNull() List<DocumentSource> sources, @NonNull() 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 .- Returns:
New instance of fragment that can be attached to view hierarchy.
-
setSelectedMeasurementValueConfiguration
void setSelectedMeasurementValueConfiguration(@NonNull() MeasurementValueConfiguration configuration)
For measurement tools, you can set and select whichever MeasurementValueConfiguration you want using this API. This will set what com.pspdfkit.annotations.measurements.Scale and com.pspdfkit.annotations.measurements.MeasurementPrecision you want to use.
- Parameters:
configuration
- the MeasurementValueConfiguration to set
-
getInternal
@RestrictTo(value = RestrictTo.Scope.LIBRARY_GROUP) InternalPdfFragmentApi getInternal()
Returns the InternalPdfFragmentApi. Internal usage only.
-
getState
@NonNull() Bundle getState()
Gets current state of the fragment.
- Returns:
Fragment's state or
null
if views are not ready yet.
-
onCreateView
@Nullable() View onCreateView(@NonNull() LayoutInflater inflater, @Nullable() ViewGroup container, @Nullable() Bundle savedInstanceState)
-
onViewCreated
void onViewCreated(@NonNull() View view, @Nullable() Bundle savedInstanceState)
-
onResume
void onResume()
-
refreshPages
void refreshPages()
Re initialises DocumentView if total number of visible pages are 0. This is useful when the document is loaded but the pages are cleared for example when this is used in a ViewPager.
-
onSaveInstanceState
void onSaveInstanceState(@NonNull() 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.
-
onConfigurationChanged
void onConfigurationChanged(@NonNull() Configuration newConfig)
-
onStop
void onStop()
-
onLowMemory
void onLowMemory()
-
onDestroyView
void onDestroyView()
-
onDestroy
void onDestroy()
-
onDetach
void onDetach()
-
save
boolean 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 and the document was actually modified.Blocks the current thread until saving has finished.
- Returns:
Returns true if document had been modified and was successfully saved.
-
saveAsync
void saveAsync()
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 and the document was actually modified.Runs the save on a thread so a spinner is shown on the UI while saving is happening. NOTE: If you run into corrupted files after using this function, use the safer save
-
getDocument
@Nullable() PdfDocument getDocument()
Gets the loaded document.
- Returns:
Document loaded into the fragment.
-
setSelectedAnnotation
@UiThread() void setSelectedAnnotation(@NonNull() Annotation annotation)
Selects a single Annotation. This will also start annotation editing mode with selected annotation being edited.
- Parameters:
annotation
- The Annotation to select
-
getSelectedAnnotations
@NonNull() 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.
-
setSelectedAnnotations
@UiThread() void setSelectedAnnotations(@NonNull() Collection<out Annotation> annotations)
Sets the currently selected Annotations.
- Parameters:
annotations
- The Annotations to select.
-
clearSelectedAnnotations
@UiThread() 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.
-
addAnnotationToPage
void addAnnotationToPage(@NonNull() 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.
-
addAnnotationToPage
void addAnnotationToPage(@NonNull() Annotation annotation, boolean selectImmediately, @Nullable() 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.completeAction
- Action that should be executed immediately after annotation has been added to the page.
-
getSelectedFormElement
@Nullable() FormElement getSelectedFormElement()
Returns currently selected form element.
- Returns:
Currently selected form element,
null
if no element is selected.
-
setSelectedFormElement
@UiThread() void setSelectedFormElement(@NonNull() FormElement formElement)
Sets the currently selected FormElement.
- Parameters:
formElement
- The FormElement to select.
-
getPageIndex
@IntRange(from = "-1") int getPageIndex()
Gets currently displayed document page.
- Returns:
Currently displayed document page,
-1
if document isnull
.
-
getPageCount
@IntRange(from = "-1") int getPageCount()
Gets number of pages in the document.
- Returns:
Number of pages in the displayed document,
-1
if document isnull
.
-
getSiblingPageIndex
@IntRange(from = "-1") int getSiblingPageIndex(@IntRange(from = "-1") 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.
-
setPageIndex
@UiThread() void setPageIndex(@IntRange(from = 0) 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.This method will throw an exception if
pageIndex < 0 || pageIndex >= pageCount
(as returned by getPageCount).- Parameters:
pageIndex
- Target page which should be displayed.
-
setPageIndex
@UiThread() void setPageIndex(@IntRange(from = 0) int pageIndex, boolean animated)
Sets the
pageIndex
to be displayed (0 is the first one). Ifanimated
is set totrue
, the page jump will be animated. Iffalse
, thepage
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 totrue
, if a transitioning animation should be performed.
-
zoomBy
void zoomBy(int focusX, int focusY, @IntRange(from = 0) 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).
-
zoomTo
void zoomTo(int focusX, int focusY, @IntRange(from = 0) 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).
-
zoomTo
void zoomTo(RectF rect, @IntRange(from = 0) 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.
-
getZoomScale
float getZoomScale(@IntRange(from = 0) 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.
-
scrollTo
void scrollTo(@NonNull() RectF pdfRect, @IntRange(from = 0) int pageIndex, long duration, boolean scrollWhenVisible)
Scrolls to the given
pdfRect
, if necessary changing to thepage
. This will keep the current zoom level. IfscrollWhenVisible
isfalse
this method will be a no-op if thepdfRect
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.
-
setCustomPdfSource
void setCustomPdfSource(@NonNull() DocumentSource source)
Sets the custom source for the PDF file.
- Parameters:
source
- PDF document source.
-
setCustomPdfSources
void setCustomPdfSources(@NonNull() List<DocumentSource> sources)
Sets the custom sources for the PDF file.
- Parameters:
sources
- List of PDF document sources.
-
getBackgroundColor
@ColorInt() 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.
-
setBackgroundColor
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.
-
isScrollingEnabled
boolean isScrollingEnabled()
Indicates whether the scrolling is enabled, or not.
- Returns:
true
if scrolling is enabled,false
otherwise.
-
setScrollingEnabled
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.
-
isZoomingEnabled
boolean isZoomingEnabled()
Indicates whether the zooming is enabled, or not.
- Returns:
true
if zooming is enabled,false
otherwise.
-
setZoomingEnabled
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.
-
isImageDocument
boolean isImageDocument()
Indicates whether the displayed document is an image or not.
- Returns:
true
if the displayed document is image,false
otherwise.
-
getViewProjection
@NonNull() 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.
-
getVisiblePdfRect
boolean getVisiblePdfRect(@NonNull() RectF targetRect, @IntRange(from = 0) int pageIndex)
Sets
targetRect
to contain the visible PDF rect of the givenpageIndex
. If thepageIndex
is not visible on the screen,targetRect
won't be modified and the method will returnfalse
.- Parameters:
targetRect
- RectF instance which will be set to the visible PDF rect.pageIndex
- Target page number.- Returns:
true
if the page visible and its visible rect was written totargetRect
, orfalse
if the page is not visible andtargetRect
was not modified.
-
getVisiblePages
@NonNull() List<Integer> getVisiblePages()
Fetch the list of pages currently visible on the screen.
- Returns:
List of page numbers of visible pages.
-
setOnPreparePopupToolbarListener
void setOnPreparePopupToolbarListener(@Nullable() 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.
-
addDocumentListener
void addDocumentListener(@NonNull() 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.
-
removeDocumentListener
void removeDocumentListener(@NonNull() 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.
-
addDocumentScrollListener
void addDocumentScrollListener(@NonNull() 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.
-
removeDocumentScrollListener
void removeDocumentScrollListener(@NonNull() 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.
-
notifyAnnotationHasChanged
void notifyAnnotationHasChanged(@NonNull() 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. If you see annotations not rendering during zooming or page transitions, you probably need to call this function.
- Parameters:
annotation
- Annotation that has changed.
-
notifyAnnotationsHaveChanged
void notifyAnnotationsHaveChanged(@NonNull() List<out Annotation> annotations)
Notifies this fragment that the passed annotations have changed and that all the views displaying it should be updated. Calling this method before document is loaded will have no effect.
- Parameters:
annotations
- Annotation that have changed.
-
beginNavigation
@UiThread() void beginNavigation()
Notifies the navigation manager that calls to setPageIndex should be added to the navigation history until endNavigation is called.
-
endNavigation
@UiThread() void endNavigation()
Commits the page changes to the navigation history dropping everything but the very last one.
-
executeAction
void executeAction(@NonNull() Action action)
Executes the given PDF
action
on the currently loaded document.- Parameters:
action
- Action that should be executed.
-
executeAction
void executeAction(@NonNull() Action action, @Nullable() 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.
-
addDocumentActionListener
void addDocumentActionListener(@NonNull() 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.
-
removeDocumentActionListener
void removeDocumentActionListener(@NonNull() 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. Addingnull
is not allowed, and will result in an exception.- Parameters:
listener
- DocumentActionListener that should be removed.
-
onDocumentLoaded
@UiThread() void onDocumentLoaded(@NonNull() 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.
-
getAnnotationCreator
@NonNull() String getAnnotationCreator()
-
getRecordedListener
@NonNull() OnEditRecordedListener getRecordedListener()
-
onAnnotationsCopied
void onAnnotationsCopied(@NonNull() List<out Annotation> annotations)
The following listener methods are called after successful operation. They might be called from a background thread, be careful when accessing the UI from there
-
onAnnotationsPasted
void onAnnotationsPasted(@NonNull() List<out Annotation> annotations)
-
onAnnotationsCut
void onAnnotationsCut(@NonNull() List<out Annotation> annotations)
-
onDocumentLoadFailed
@UiThread() void onDocumentLoadFailed(@NonNull() Throwable exception)
Called if document loading has failed.
- Parameters:
exception
- Cause of the loading failure.
-
onDocumentSave
@UiThread() boolean onDocumentSave(@NonNull() PdfDocument document, @NonNull() 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.- Returns:
true
if the document should be saved,false
if saving should be cancelled.
-
onDocumentSaved
@UiThread() void onDocumentSaved(@NonNull() PdfDocument document)
Called after the document has been saved.
- Parameters:
document
- Instance of document that was saved.
-
onDocumentSaveFailed
@UiThread() void onDocumentSaveFailed(@NonNull() PdfDocument document, @NonNull() Throwable exception)
Called if document saving has failed.
- Parameters:
exception
- Cause of the saving failure if applicable.
-
onDocumentSaveCancelled
void onDocumentSaveCancelled(@NonNull() PdfDocument document)
Called if document saving has been cancelled.
- Parameters:
document
- Instance of document that was saved.
-
onPageClick
boolean onPageClick(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex, @Nullable() MotionEvent event, @Nullable() PointF pagePosition, @Nullable() 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.pagePosition
- Tapped page position (in PDF page coordinates with origin on bottom left).clickedAnnotation
- Annotation that was tapped, ornull
if no annotation was tapped.- Returns:
true
if tap was handled by thisDocumentListener
and should not be handled by PSPDFKit anymore. If returningfalse
PSPDFKit will continue executing it's default action.
-
onDocumentClick
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 orfalse
if PSPDFKit should execute it's default action.
-
onPageChanged
void onPageChanged(@NonNull() PdfDocument document, @IntRange(from = 0) int pageIndex)
Called when user scrolled to a new page.
- Parameters:
document
- Currently opened document.pageIndex
- Page number of new page.
-
onDocumentZoomed
void onDocumentZoomed(@NonNull() PdfDocument document, @IntRange(from = 0) 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.
-
onPageUpdated
void onPageUpdated(@NonNull() PdfDocument document, @IntRange(from = 0) 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.
-
getPasswordView
@NonNull() PdfPasswordView getPasswordView()
Returns currently set password view for the fragment.
- Returns:
password view currently set on the fragment.
-
setPasswordView
void setPasswordView(@NonNull() PdfPasswordView pdfPasswordView)
Sets password view to be used for the password-protected documents.
- Parameters:
pdfPasswordView
- The password view to use.
-
getAnnotationConfiguration
@NonNull() 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).
- Returns:
The registry of AnnotationConfiguration for this fragment.
-
getContentEditingConfiguration
@NonNull() ContentEditingFillColorConfiguration getContentEditingConfiguration()
Returns content editing fill color configuration
Note: This method must be called after views are created (after onCreateView).
- Returns:
The ContentEditingFillColorConfiguration for this fragment.
-
getAnnotationPreferences
@NonNull() AnnotationPreferencesManager getAnnotationPreferences()
Returns manager for annotation preferences.
Note: This method must be called after views are created (after onCreateView).
- Returns:
The annotation preferences manager of this fragment.
-
getContentEditingPreferences
@NonNull() ContentEditingPreferencesManager getContentEditingPreferences()
Returns manager for content editing preferences.
Note: This method must be called after views are created (after onCreateView).
- Returns:
The content editing preferences manager of this fragment.
-
addDrawableProvider
void addDrawableProvider(@NonNull() 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.
-
removeDrawableProvider
void removeDrawableProvider(@NonNull() 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.
-
addOverlayViewProvider
void addOverlayViewProvider(@NonNull() 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.
-
removeOverlayViewProvider
void removeOverlayViewProvider(@NonNull() 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.
-
addOnAnnotationSelectedListener
void addOnAnnotationSelectedListener(@NonNull() AnnotationManager.OnAnnotationSelectedListener listener)
Register a 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.
-
removeOnAnnotationSelectedListener
void removeOnAnnotationSelectedListener(@NonNull() AnnotationManager.OnAnnotationSelectedListener listener)
Remove a previously registered OnAnnotationSelectedListener. If the provider hasn't been registered previously, this method will be a no-op.
- Parameters:
listener
- Listener to unregister.
-
addOnAnnotationDeselectedListener
void addOnAnnotationDeselectedListener(@NonNull() AnnotationManager.OnAnnotationDeselectedListener listener)
Register a 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.
-
removeOnAnnotationDeselectedListener
void removeOnAnnotationDeselectedListener(@NonNull() AnnotationManager.OnAnnotationDeselectedListener listener)
Remove a previously registered OnAnnotationDeselectedListener. If the provider hasn't been registered previously, this method will be a no-op.
- Parameters:
listener
- Listener to unregister.
-
addOnAnnotationUpdatedListener
void addOnAnnotationUpdatedListener(@NonNull() 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.
-
removeOnAnnotationUpdatedListener
void removeOnAnnotationUpdatedListener(@NonNull() 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.
-
addOnAnnotationCreationModeChangeListener
void addOnAnnotationCreationModeChangeListener(@NonNull() AnnotationManager.OnAnnotationCreationModeChangeListener listener)
Register a 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.
-
removeOnAnnotationCreationModeChangeListener
void removeOnAnnotationCreationModeChangeListener(@NonNull() AnnotationManager.OnAnnotationCreationModeChangeListener listener)
Remove a previously registered OnAnnotationCreationModeChangeListener. If the provider hasn't been registered previously, this method will be a no-op.
- Parameters:
listener
- Listener to unregister.
-
addOnAnnotationCreationModeSettingsChangeListener
void addOnAnnotationCreationModeSettingsChangeListener(@NonNull() AnnotationManager.OnAnnotationCreationModeSettingsChangeListener listener)
Register a 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.
-
removeOnAnnotationCreationModeSettingsChangeListener
void removeOnAnnotationCreationModeSettingsChangeListener(@NonNull() AnnotationManager.OnAnnotationCreationModeSettingsChangeListener listener)
Remove a previously registered OnAnnotationCreationModeSettingsChangeListener. If the provider hasn't been registered previously, this method will be a no-op.
- Parameters:
listener
- Listener to unregister.
-
addOnAnnotationEditingModeChangeListener
void addOnAnnotationEditingModeChangeListener(@NonNull() AnnotationManager.OnAnnotationEditingModeChangeListener listener)
Register a 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.
-
removeOnAnnotationEditingModeChangeListener
void removeOnAnnotationEditingModeChangeListener(@NonNull() AnnotationManager.OnAnnotationEditingModeChangeListener listener)
Remove a previously registered OnAnnotationEditingModeChangeListener. If the provider hasn't been registered previously, this method will be a no-op.
- Parameters:
listener
- Listener to unregister.
-
addOnContentEditingModeChangeListener
void addOnContentEditingModeChangeListener(@NonNull() ContentEditingManager.OnContentEditingModeChangeListener listener)
-
removeOnContentEditingModeChangeListener
void removeOnContentEditingModeChangeListener(@NonNull() ContentEditingManager.OnContentEditingModeChangeListener listener)
-
addOnContentEditingContentChangeListener
void addOnContentEditingContentChangeListener(@NonNull() ContentEditingManager.OnContentEditingContentChangeListener listener)
-
removeOnContentEditingContentChangeListener
void removeOnContentEditingContentChangeListener(@NonNull() ContentEditingManager.OnContentEditingContentChangeListener listener)
-
setInsets
void setInsets(@IntRange(from = 0) int left, @IntRange(from = 0) int top, @IntRange(from = 0) int right, @IntRange(from = 0) 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.
-
addInsets
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.
-
enterContentEditingMode
void enterContentEditingMode()
Starts the content editing mode which allows for modifying PDF content text
-
enterAnnotationCreationMode
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.
-
enterAnnotationCreationMode
void enterAnnotationCreationMode(@NonNull() AnnotationTool annotationTool)
Enter annotation creation mode on the document. Once you invoke this method, you'll get AnnotationCreationController (through registered ) 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.
-
enterAnnotationCreationMode
void enterAnnotationCreationMode(@NonNull() AnnotationTool annotationTool, @NonNull() AnnotationToolVariant annotationToolVariant)
Enter annotation creation mode on the document. Once you invoke this method, you'll get AnnotationCreationController (through registered ) 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.annotationToolVariant
- Specifies the variant of the annotation tool in which to start this mode.
-
enterTextSelectionMode
void enterTextSelectionMode(@IntRange(from = 0) int pageIndex, @NonNull() Range textRange)
Sets the current text selection. Once you invoke this method, you'll get (through registered ) which provides methods for managing text selection actions.
- Parameters:
pageIndex
- Number of the page on which text selection should be performed.textRange
- 0-based range spanning the text which should be selected.
-
enterTextSelectionMode
void enterTextSelectionMode(int pageIndex, @NonNull() TextSelectionRectangles touchedTextRects)
Sets the current text selection. Once you invoke this method, you'll get (through registered ) which provides methods for managing text selection actions.
- Parameters:
pageIndex
- Number of the page on which text selection should be performed.touchedTextRects
- List of rectangles (in PDF coordinates) under which text selection is to be performed
-
enterAnnotationEditingMode
void enterAnnotationEditingMode(@NonNull() List<Annotation> annotations)
Enter annotation editing mode on the document. Once you invoke this method, you'll get (through registered ) which provides methods for editing a selected annotation. Notice: this method will not select annotation on the screen, for that use setSelectedAnnotation.
- Parameters:
annotations
- Annotation to be edited.
-
enterAnnotationEditingMode
void enterAnnotationEditingMode(@NonNull() Annotation annotation)
Enter annotation editing mode on the document. Once you invoke this method, you'll get (through registered ) which provides methods for editing selected annotations. Notice: this method will not select annotation on the screen, for that use setSelectedAnnotation.
- Parameters:
annotation
- Annotation to be edited.
-
enterFormEditingMode
void enterFormEditingMode(@NonNull() FormElement formElement)
Enter form editing mode on the document. Once you invoke this method, you'll get (through registered OnFormElementEditingModeChangeListener) which provides methods for editing a selected form element. Notice: this method will not select form element on the screen, for that use setSelectedFormElement.
- Parameters:
formElement
- Form element to be edited.
-
exitCurrentlyActiveMode
void exitCurrentlyActiveMode()
Exit any currently active mode on the document (annotation creation, annotation editing, text selection).
-
isInSpecialMode
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.
-
getActiveAnnotationTool
@Nullable() AnnotationTool getActiveAnnotationTool()
Returns the active annotation tool.
- Returns:
Active annotation tool.
-
getActiveAnnotationToolVariant
@Nullable() AnnotationToolVariant getActiveAnnotationToolVariant()
Returns the variant of the active annotation tool variant (if any).
- Returns:
Active annotation tool variant.
-
getTextSelection
@Nullable() TextSelection getTextSelection()
Returns the current text selection.
- Returns:
Current text selection, or
null
if no text is selected.
-
getContentEditingState
ContentEditingState getContentEditingState()
Returns the current content editing state.
- Returns:
Current content editing data, or
null
if content editing is not active.
-
addOnTextSelectionModeChangeListener
void addOnTextSelectionModeChangeListener(@NonNull() TextSelectionManager.OnTextSelectionModeChangeListener listener)
Adds a 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.
-
removeOnTextSelectionModeChangeListener
void removeOnTextSelectionModeChangeListener(@NonNull() TextSelectionManager.OnTextSelectionModeChangeListener listener)
Removes a previously added 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.
-
addOnTextSelectionChangeListener
void addOnTextSelectionChangeListener(@NonNull() TextSelectionManager.OnTextSelectionChangeListener listener)
Adds a 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.
-
removeOnTextSelectionChangeListener
void removeOnTextSelectionChangeListener(@NonNull() TextSelectionManager.OnTextSelectionChangeListener listener)
Removes a 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.
-
onAnnotationDeselected
void onAnnotationDeselected(@NonNull() 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).
-
onPrepareAnnotationSelection
boolean onPrepareAnnotationSelection(@NonNull() AnnotationSelectionController controller, @NonNull() 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:
true
when you want AnnotationSelectionController to proceed with the selection. Returningfalse
will prevent annotation from being selected.
-
onAnnotationSelected
void onAnnotationSelected(@NonNull() 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 .
-
onAnnotationSelectionFinished
void onAnnotationSelectionFinished(@NonNull() List<Annotation> annotations, boolean annotationCreated)
Called when annotation gets selected.
- Parameters:
annotations
- Annotation that were selected.
-
onFormElementSelected
void onFormElementSelected(@NonNull() FormElement formElement)
Called when form element gets selected.
- Parameters:
formElement
- Form element that is being selected.
-
onFormElementDeselected
void onFormElementDeselected(@NonNull() 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).
-
onScrollStateChanged
void onScrollStateChanged(@NonNull() ScrollState state)
Called whenever the current scroll state of the document view has changed.
- Parameters:
state
- The new scroll state.
-
onDocumentScrolled
void onDocumentScrolled(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
andmaxY
are not guaranteed to remain the same between two calls.- Parameters:
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.
-
notifyLayoutChanged
void notifyLayoutChanged()
Notifies layout has changed and properly updates its internal state and views. Call this when
PdfFragment
is embedded in aViewGroup
that has changed its size, this will schedule a layout pass of the view tree, after views have been laid out.
-
addOnFormElementSelectedListener
void addOnFormElementSelectedListener(@NonNull() FormManager.OnFormElementSelectedListener listener)
Adds a 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.
-
removeOnFormElementSelectedListener
void removeOnFormElementSelectedListener(@NonNull() FormManager.OnFormElementSelectedListener listener)
Removes a previously registered 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. Addingnull
is not allowed,and will result in an exception.- Parameters:
listener
- OnFormElementSelectedListener that should be removed.
-
addOnFormElementDeselectedListener
void addOnFormElementDeselectedListener(@NonNull() FormManager.OnFormElementDeselectedListener listener)
Adds a 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.
-
removeOnFormElementDeselectedListener
void removeOnFormElementDeselectedListener(@NonNull() FormManager.OnFormElementDeselectedListener listener)
Removes a previously registered 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. Addingnull
is not allowed,and will result in an exception.- Parameters:
listener
- OnFormElementDeselectedListener that should be removed.
-
addOnFormElementUpdatedListener
void addOnFormElementUpdatedListener(@NonNull() FormManager.OnFormElementUpdatedListener listener)
Adds a 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.
-
removeOnFormElementUpdatedListener
void removeOnFormElementUpdatedListener(@NonNull() FormManager.OnFormElementUpdatedListener listener)
Removes a previously registered 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. Addingnull
is not allowed,and will result in an exception.- Parameters:
listener
- OnFormElementUpdatedListener that should be removed.
-
addOnFormElementEditingModeChangeListener
void addOnFormElementEditingModeChangeListener(@NonNull() FormManager.OnFormElementEditingModeChangeListener listener)
Adds a 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.
-
removeOnFormElementEditingModeChangeListener
void removeOnFormElementEditingModeChangeListener(@NonNull() FormManager.OnFormElementEditingModeChangeListener listener)
Removes a previously registered 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. Addingnull
is not allowed,and will result in an exception.- Parameters:
listener
- OnFormElementEditingModeChangeListener that should be removed.
-
addOnFormElementClickedListener
void addOnFormElementClickedListener(@NonNull() FormManager.OnFormElementClickedListener listener)
Adds a 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.
-
removeOnFormElementClickedListener
void removeOnFormElementClickedListener(@NonNull() FormManager.OnFormElementClickedListener listener)
Removes a previously registered 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. Addingnull
is not allowed,and will result in an exception.- Parameters:
listener
- OnFormElementClickedListener that should be removed.
-
addOnFormElementViewUpdatedListener
void addOnFormElementViewUpdatedListener(@NonNull() FormManager.OnFormElementViewUpdatedListener listener)
Adds a 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.
-
removeOnFormElementViewUpdatedListener
void removeOnFormElementViewUpdatedListener(@NonNull() FormManager.OnFormElementViewUpdatedListener listener)
Removes a previously registered 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. Addingnull
is not allowed, and will result in an exception.- Parameters:
listener
- OnFormElementViewUpdatedListener that should be removed.
-
getUndoManager
@NonNull() 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.
-
getContentEditingUndoManager
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.
-
getAudioModeManager
@NonNull() AudioModeManager getAudioModeManager()
Returns this fragment's audio mode manager instance for entering/leaving audio playback or recording modes.
- Returns:
AudioModeManager used for handling audio modes on this fragment.
-
setOverlaidAnnotationTypes
void setOverlaidAnnotationTypes(@NonNull() 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.
-
getOverlaidAnnotationTypes
@NonNull() EnumSet<AnnotationType> getOverlaidAnnotationTypes()
Gets annotation types that should be rendered as overlays.
- Returns:
Set of annotation types that are enabled for overlay rendering.
-
setOverlaidAnnotations
void setOverlaidAnnotations(@NonNull() 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.
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.
- Parameters:
overlayAnnotations
- List of annotations that should be rendered as overlays.
-
getOverlaidAnnotations
@NonNull() List<Annotation> getOverlaidAnnotations()
Gets annotations that should be rendered as overlays.
- Returns:
List of annotations that should be rendered as overlays.
-
setAnnotationOverlayRenderStrategy
void setAnnotationOverlayRenderStrategy(@Nullable() 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 .
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.
-
setPageLoadingDrawable
void setPageLoadingDrawable(@Nullable() 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.
-
isRedactionAnnotationPreviewEnabled
boolean isRedactionAnnotationPreviewEnabled()
Returns redaction annotation preview mode,
false
by default.- Returns:
true
if redaction annotation preview mode is enabled,false
otherwise.
-
addAnnotationViewsListener
void addAnnotationViewsListener(@NonNull() AnnotationViewsListener listener)
Adds an AnnotationViewsListener to the list of listeners that will be notified when the internal views factory creates an EditText widget for editing a freetext annotation
- Parameters:
listener
- to be added
-
removeAnnotationViewsListener
void removeAnnotationViewsListener(@NonNull() AnnotationViewsListener listener)
Removes a listener from the list of AnnotationViewsListeners.
- Parameters:
listener
- to be removed
-
setOnDocumentLongPressListener
void setOnDocumentLongPressListener(@Nullable() 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, ornull
to clear the listener.
-
setRedactionAnnotationPreviewEnabled
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.
-
-
-
-