PdfFragment

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.

Inheritors

Constructors

Link copied to clipboard
constructor()
This constructor is for internal usage only.

Properties

Link copied to clipboard
Link copied to clipboard
val DEFAULT_ZOOM: Float = 1.0f
Default zoom scale.
Link copied to clipboard
Link copied to clipboard
val DOCUMENTSTORE_KEY_LAST_VIEWED_PAGE_INDEX: String = "PSPDFKit.lastViewedPage"
Key for storing the last viewed page index inside the DocumentDataStore of the loaded document.
Link copied to clipboard
If the fragment is created from an image document source, the loaded image document will be stored here.
Link copied to clipboard
Indicates whether the document view is enabled right now, if it's disabled, scrolling and zooming is not possible.
Link copied to clipboard
Indicates whether UI is enabled right now.
Link copied to clipboard
val MAX_ZOOM: Float = 15.0f
Maximum zoom scale.
Link copied to clipboard
val MIN_ZOOM: Float = 0.8f
Min allowed zoom (before snapping back).
Link copied to clipboard
Navigation history to jump between pages when clicking links.
Link copied to clipboard
val PARAM_CONFIGURATION: String = "PSPDFKit.Configuration"
Link copied to clipboard
val PARAM_IMAGE_DOCUMENT_SOURCE: String = "PSPDFKit.ImageDocument.Source"
Link copied to clipboard
val PARAM_SOURCES: String = "PSPDFKit.Sources"
Link copied to clipboard
open var signatureMetadata: SignatureMetadata
Currently used metadata for digital signatures.
Link copied to clipboard
Currently used custom signature storage.

Functions

Link copied to clipboard
open fun addAnnotationToPage(@NonNull annotation: Annotation, selectImmediately: Boolean)
open fun addAnnotationToPage(@NonNull annotation: Annotation, selectImmediately: Boolean, @Nullable completeAction: Runnable)
Adds annotation to page asynchronously, refreshing rendering in all UI components.
Link copied to clipboard
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
Link copied to clipboard
Adds a DocumentActionListener that can handle actions bound to PDF objects.
Link copied to clipboard
open fun addDocumentListener(@NonNull documentListener: DocumentListener)
Adds a DocumentListener for listening to document events.
Link copied to clipboard
open fun addDocumentScrollListener(@NonNull documentScrollListener: DocumentScrollListener)
Adds a DocumentScrollListener for listening to scrolling events on the document.
Link copied to clipboard
open fun addDrawableProvider(@NonNull drawableProvider: PdfDrawableProvider)
Adds a PdfDrawableProvider to be managed by this object.
Link copied to clipboard
open fun addInsets(leftOffset: Int, topOffset: Int, rightOffset: Int, bottomOffset: Int)
Offset PdfFragment insets by specified amount.
Register a OnAnnotationCreationModeChangeListener to get notified when annotation creation mode gets updated.
Link copied to clipboard
Register a OnAnnotationDeselectedListener to get notified when annotation gets deselected.
Link copied to clipboard
Register a OnAnnotationEditingModeChangeListener to get notified when annotation editing mode gets updated.
Link copied to clipboard
Register a OnAnnotationSelectedListener to get notified when annotation gets selected.
Link copied to clipboard
Link copied to clipboard
Adds a OnFormElementClickedListener to get notified when form element has been clicked.
Link copied to clipboard
Adds a OnFormElementDeselectedListener to get notified when form element gets deselected.
Adds a OnFormElementEditingModeChangeListener to get notified when form element editing mode gets updated.
Link copied to clipboard
Adds a OnFormElementSelectedListener to get notified when form element gets selected.
Link copied to clipboard
Adds a OnFormElementUpdatedListener to get notified when form element gets updated.
Link copied to clipboard
Adds a OnFormElementViewUpdatedListener to get notified about form element view update events.
Link copied to clipboard
Adds a OnTextSelectionChangeListener, which gets notified when text selection changes in the document, such as different text is selected.
Link copied to clipboard
Adds a OnTextSelectionModeChangeListener, which gets notified when entering and exiting a text selection in the document.
Link copied to clipboard
open fun addOverlayViewProvider(@NonNull overlayViewProvider: OverlayViewProvider)
Adds an OverlayViewProvider for adding overlay views to this fragment.
Link copied to clipboard
Notifies the navigation manager that calls to setPageIndex should be added to the navigation history until endNavigation is called.
Link copied to clipboard
Clears all currently selected Annotations.
Link copied to clipboard
Commits the page changes to the navigation history dropping everything but the very last one.
Link copied to clipboard
Starts the annotation creation mode with the last used annotation tool as the selected one.
open fun enterAnnotationCreationMode(@NonNull annotationTool: AnnotationTool, @NonNull annotationToolVariant: AnnotationToolVariant)
Enter annotation creation mode on the document.
Link copied to clipboard
Enter annotation editing mode on the document.
Link copied to clipboard
Starts the content editing mode which allows for modifying PDF content text
Link copied to clipboard
open fun enterFormEditingMode(@NonNull formElement: FormElement)
Enter form editing mode on the document.
Link copied to clipboard
open fun enterTextSelectionMode(@IntRange(from = 0) pageIndex: Int, @NonNull textRange: Range)
open fun enterTextSelectionMode(pageIndex: Int, @NonNull touchedTextRects: TextSelectionRectangles)
Sets the current text selection.
Link copied to clipboard
open fun executeAction(@NonNull action: Action)
open fun executeAction(@NonNull action: Action, @Nullable actionSender: ActionSender)
Executes the given PDF action on the currently loaded document.
Link copied to clipboard
Exit any currently active mode on the document (annotation creation, annotation editing, text selection).
Link copied to clipboard
Returns the active annotation tool.
Link copied to clipboard
Returns the variant of the active annotation tool variant (if any).
Link copied to clipboard
Returns annotation configuration registry with annotation configuration for supported annotation types and/or tools.
Link copied to clipboard
Link copied to clipboard
Returns manager for annotation preferences.
Link copied to clipboard
Returns this fragment's audio mode manager instance for entering/leaving audio playback or recording modes.
Link copied to clipboard
Gets the background color of the fragment.
Link copied to clipboard
Returns content editing fill color configuration Note: This method must be called after views are created (after onCreateView).
Link copied to clipboard
Returns manager for content editing preferences.
Link copied to clipboard
open fun getContentEditingState(): ContentEditingState
Returns the current content editing state.
Link copied to clipboard
Returns this fragment's undo manager instance for performing undo/redo operations of content edits.
Link copied to clipboard
Gets the loaded document.
Link copied to clipboard
open fun getInternal(): InternalPdfFragmentApi
Returns the InternalPdfFragmentApi.
Link copied to clipboard
Gets annotations that should be rendered as overlays.
Link copied to clipboard
Gets annotation types that should be rendered as overlays.
Link copied to clipboard
@IntRange(from = "-1")
open fun getPageCount(): Int
Gets number of pages in the document.
Link copied to clipboard
@IntRange(from = "-1")
open fun getPageIndex(): Int
Gets currently displayed document page.
Link copied to clipboard
Returns currently set password view for the fragment.
Link copied to clipboard
open fun getRecordedListener(): OnEditRecordedListener
Link copied to clipboard
Returns a list of currently selected annotations, or an empty list if no annotations were selected.
Link copied to clipboard
Returns currently selected form element.
Link copied to clipboard
@IntRange(from = "-1")
open fun getSiblingPageIndex(@IntRange(from = "-1") pageIndex: Int): Int
Gets page sibling index (usable in double page mode).
Link copied to clipboard
open fun getState(): Bundle
Gets current state of the fragment.
Link copied to clipboard
Returns the current text selection.
Link copied to clipboard
Returns this fragment's undo manager instance for performing undo/redo operations of annotation edits.
Link copied to clipboard
Returns the ViewProjection for transforming between the view coordinates and PDF coordinates.
Link copied to clipboard
Fetch the list of pages currently visible on the screen.
Link copied to clipboard
open fun getVisiblePdfRect(@NonNull targetRect: RectF, @IntRange(from = 0) pageIndex: Int): Boolean
Sets targetRect to contain the visible PDF rect of the given pageIndex.
Link copied to clipboard
open fun getZoomScale(@IntRange(from = 0) pageIndex: Int): Float
Gets zoom scale at the specified page.
Link copied to clipboard
Indicates whether the displayed document is an image or not.
Link copied to clipboard
Returns true if any of the special modes is active.
Link copied to clipboard
Returns redaction annotation preview mode, false by default.
Link copied to clipboard
Indicates whether the scrolling is enabled, or not.
Link copied to clipboard
Indicates whether the zooming is enabled, or not.
Link copied to clipboard
open fun newImageInstance(@NonNull documentUri: Uri, @NonNull configuration: PdfConfiguration): PdfFragment
Creates and returns a new Fragment to display a converted PDF document from a supported image format.
Link copied to clipboard
open fun newInstance(@NonNull documentUri: Uri, @NonNull configuration: PdfConfiguration): PdfFragment
open fun newInstance(@NonNull documentUri: Uri, @Nullable password: String, @NonNull configuration: PdfConfiguration): PdfFragment
open fun newInstance(@NonNull documentUri: Uri, @Nullable password: String, @Nullable contentSignature: String, @NonNull configuration: PdfConfiguration): PdfFragment
Creates and returns a new Fragment to display a PDF document.
open fun newInstance(@NonNull document: PdfDocument, @NonNull configuration: PdfConfiguration): PdfFragment
Creates and returns a new Fragment to display a PDF document from an already opened instance.
open fun newInstance(@NonNull fragment: PdfFragment, @NonNull configuration: PdfConfiguration): PdfFragment
Creates and returns a new Fragment to display a PDF document from an PdfFragment.
open fun newInstance(@NonNull documentUris: List<Uri>, @NonNull configuration: PdfConfiguration): PdfFragment
open fun newInstance(@NonNull documentUris: List<Uri>, @Nullable documentPasswords: List<String>, @NonNull configuration: PdfConfiguration): PdfFragment
open fun newInstance(@NonNull documentUris: List<Uri>, @Nullable documentPasswords: List<String>, @Nullable documentContentSignatures: List<String>, @NonNull configuration: PdfConfiguration): PdfFragment
Creates and returns a new Fragment to display passed list of PDF documents as a single compound document.
open fun newInstance(@NonNull source: DataProvider, @Nullable password: String, @NonNull configuration: PdfConfiguration): PdfFragment
Creates and returns a new Fragment to display a PDF document from a custom data source.
open fun newInstance(@NonNull source: DataProvider, @Nullable password: String, @Nullable contentSignature: String, @NonNull configuration: PdfConfiguration): PdfFragment
Creates and returns a new Fragment to display a PDF document from a custom data source
Link copied to clipboard
Creates and returns a new Fragment to display a PDF document from the given DocumentSources.
Link copied to clipboard
open fun newInstanceFromSources(@NonNull sources: List<DataProvider>, @Nullable passwords: List<String>, @Nullable contentSignatures: List<String>, @NonNull configuration: PdfConfiguration): PdfFragment
Creates and returns a new Fragment to display a PDF document from a custom data source as a compound document.
Link copied to clipboard
Notifies this fragment that the passed annotation has changed and that all the views displaying it should be updated.
Link copied to clipboard
open fun notifyAnnotationsHaveChanged(@NonNull annotations: List<out Annotation>)
Notifies this fragment that the passed annotations have changed and that all the views displaying it should be updated.
Link copied to clipboard
Notifies layout has changed and properly updates its internal state and views.
Link copied to clipboard
open fun onActivityCreated(@Nullable savedInstanceState: Bundle)
Link copied to clipboard
open fun onAnnotationDeselected(@NonNull annotation: Annotation, reselected: Boolean)
Called when annotation gets deselected.
Link copied to clipboard
open fun onAnnotationsCopied(@NonNull annotations: List<out Annotation>)
The following listener methods are called after successful operation.
Link copied to clipboard
open fun onAnnotationsCut(@NonNull annotations: List<out Annotation>)
Link copied to clipboard
open fun onAnnotationSelected(@NonNull annotation: Annotation, annotationCreated: Boolean)
Called when annotation gets selected.
Link copied to clipboard
open fun onAnnotationSelectionFinished(@NonNull annotations: List<Annotation>, annotationCreated: Boolean)
Called when annotation gets selected.
Link copied to clipboard
open fun onAnnotationsPasted(@NonNull annotations: List<out Annotation>)
Link copied to clipboard
open fun onAttach(@NonNull context: Context)
Link copied to clipboard
Link copied to clipboard
open fun onCreate(savedInstanceState: Bundle)
Link copied to clipboard
open fun onCreateView(@NonNull inflater: LayoutInflater, @Nullable container: ViewGroup, @Nullable savedInstanceState: Bundle): View
Link copied to clipboard
open fun onDestroy()
Link copied to clipboard
open fun onDestroyView()
Link copied to clipboard
open fun onDetach()
Link copied to clipboard
Called when the user taps / clicks on the document, not the page itself but on the side (if visible).
Link copied to clipboard
Called when document is successfully loaded and the document view has been laid out.
Link copied to clipboard
Called if document loading has failed.
Link copied to clipboard
Called before document will be saved.
Link copied to clipboard
Called if document saving has been cancelled.
Link copied to clipboard
Called after the document has been saved.
Link copied to clipboard
Called if document saving has failed.
Link copied to clipboard
open fun onDocumentScrolled(@NonNull fragment: PdfFragment, currX: Int, currY: Int, maxX: Int, maxY: Int, extendX: Int, extendY: Int)
Called whenever the document in the fragment scrolled.
Link copied to clipboard
open fun onDocumentZoomed(@NonNull document: PdfDocument, @IntRange(from = 0) pageIndex: Int, scaleFactor: Float)
Called when a user zooms a document.
Link copied to clipboard
open fun onFormElementDeselected(@NonNull formElement: FormElement, reselected: Boolean)
Called when form element gets deselected.
Link copied to clipboard
open fun onFormElementSelected(@NonNull formElement: FormElement)
Called when form element gets selected.
Link copied to clipboard
open fun onLowMemory()
Link copied to clipboard
open fun onPageChanged(@NonNull document: PdfDocument, @IntRange(from = 0) pageIndex: Int)
Called when user scrolled to a new page.
Link copied to clipboard
open fun onPageClick(@NonNull document: PdfDocument, @IntRange(from = 0) pageIndex: Int, @Nullable event: MotionEvent, @Nullable pagePosition: PointF, @Nullable clickedAnnotation: Annotation): Boolean
Called when user taps / clicks on the page.
Link copied to clipboard
open fun onPageUpdated(@NonNull document: PdfDocument, @IntRange(from = 0) pageIndex: Int)
Called when content of page with pageIndex has changed (for example due to annotation or form field being updated).
Link copied to clipboard
open fun onPrepareAnnotationSelection(@NonNull controller: AnnotationSelectionController, @NonNull annotation: Annotation, annotationCreated: Boolean): Boolean
Called immediately before annotation is going to be selected.
Link copied to clipboard
open fun onResume()
Link copied to clipboard
open fun onSaveInstanceState(@NonNull outState: Bundle)
Called by the activity if it requires the fragment to save its state.
Link copied to clipboard
Called whenever the current scroll state of the PdfFragment changed.
Link copied to clipboard
open fun onStop()
Link copied to clipboard
open fun onViewCreated(@NonNull view: View, @Nullable savedInstanceState: Bundle)
Link copied to clipboard
Removes a listener from the list of AnnotationViewsListeners.
Link copied to clipboard
Removes a previously added DocumentActionListener that can handle actions bound to PDF objects.
Link copied to clipboard
open fun removeDocumentListener(@NonNull documentListener: DocumentListener)
Removes a previously registered DocumentListener.
Link copied to clipboard
open fun removeDocumentScrollListener(@NonNull documentScrollListener: DocumentScrollListener)
Removes a previously registered DocumentScrollListener.
Link copied to clipboard
open fun removeDrawableProvider(@NonNull drawableProvider: PdfDrawableProvider)
Removes a previously added PdfDrawableProvider.
Link copied to clipboard
Removes a OnTextSelectionChangeListener, which gets notified when text selection changes in the document, such as different text is selected.
Link copied to clipboard
Removes a previously added OnTextSelectionModeChangeListener, which gets notified when entering and exiting a text selection in the document.
Link copied to clipboard
open fun removeOverlayViewProvider(@NonNull overlayViewProvider: OverlayViewProvider)
Removes a previously added OverlayViewProvider.
Link copied to clipboard
open fun save()
Saves the file held by the document view back to it's original location.
Link copied to clipboard
open fun scrollTo(@NonNull pdfRect: RectF, @IntRange(from = 0) pageIndex: Int, duration: Long, scrollWhenVisible: Boolean)
Scrolls to the given pdfRect, if necessary changing to the page.
Link copied to clipboard
Sets the annotation overlay render strategy.
Link copied to clipboard
open fun setBackgroundColor(backgroundColor: Int)
Sets the background color of the fragment.
Link copied to clipboard
Sets the custom source for the PDF file.
Link copied to clipboard
Sets the custom sources for the PDF file.
Link copied to clipboard
open fun setDocumentSigningListener(@Nullable documentSigningListener: DocumentSigningListener)
Sets a new DocumentSigningListener or replaces an existing one.
Link copied to clipboard
open fun setInsets(@IntRange(from = 0) left: Int, @IntRange(from = 0) top: Int, @IntRange(from = 0) right: Int, @IntRange(from = 0) bottom: Int)
Sets insets that will be used as padding for PdfFragment contents.
Link copied to clipboard
Sets a OnDocumentLongPressListener for long press document events.
Link copied to clipboard
Sets the listener that will allow you to get notified when each of the popup toolbars is prepared and ready to be displayed.
Link copied to clipboard
open fun setOverlaidAnnotations(@NonNull overlayAnnotations: List<Annotation>)
Sets annotations that should be rendered as overlays.
Link copied to clipboard
open fun setOverlaidAnnotationTypes(@NonNull overlayAnnotationTypes: EnumSet<AnnotationType>)
Sets annotation types that should be rendered as overlays.
Link copied to clipboard
open fun setPageIndex(@IntRange(from = 0) pageIndex: Int)
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.
open fun setPageIndex(@IntRange(from = 0) pageIndex: Int, animated: Boolean)
Sets the pageIndex to be displayed (0 is the first one).
Link copied to clipboard
Sets drawable that should be displayed instead of fragment's contents (i.e.
Link copied to clipboard
open fun setPasswordView(@NonNull pdfPasswordView: PdfPasswordView)
Sets password view to be used for the password-protected documents.
Link copied to clipboard
Sets redaction annotations preview as redacted.
Link copied to clipboard
open fun setScrollingEnabled(enabled: Boolean)
Enables/disabled the scrolling performed by the user.
Link copied to clipboard
Selects a single Annotation.
Link copied to clipboard
Sets the currently selected Annotations.
Link copied to clipboard
Sets the currently selected FormElement.
Link copied to clipboard
For measurement tools, you can set and select whichever MeasurementValueConfiguration you want using this API.
Link copied to clipboard
open fun setState(@NonNull state: Bundle)
Replace fragment state.
Link copied to clipboard
open fun setZoomingEnabled(enabled: Boolean)
Enables/disabled the zooming performed by the user.
Link copied to clipboard
open fun zoomBy(focusX: Int, focusY: Int, @IntRange(from = 0) pageIndex: Int, scaleFactor: Float, duration: Long)
Zoom by the given scale focused on the given point in PDF coordinates.
Link copied to clipboard
open fun zoomTo(rect: RectF, @IntRange(from = 0) pageIndex: Int, duration: Long)
Zoom to a specific rect on the given page.
open fun zoomTo(focusX: Int, focusY: Int, @IntRange(from = 0) pageIndex: Int, targetScale: Float, duration: Long)
Zoom to the given scale focused on the given point in PDF coordinates.