Class InstantPdfFragment
-
- 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.instant.listeners.InstantDocumentListener
,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 InstantPdfFragment extends PdfFragment implements InstantDocumentListener
Fragment that actually displays instant 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_INSTANT_DOCUMENT_SOURCE
-
Constructor Summary
Constructors Constructor Description InstantPdfFragment()
-
Method Summary
Modifier and Type Method Description static InstantPdfFragment
newInstance(@NonNull() String serverUrl, @NonNull() String jwt, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document downloaded from Instant Server (PSPDFKit Document Engine). static InstantPdfFragment
newInstance(@NonNull() InstantPdfDocument document, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document from an already opened instance. AnnotationPreferencesManager
getAnnotationPreferences()
Returns manager for annotation preferences. View
onCreateView(@NonNull() LayoutInflater inflater, @Nullable() ViewGroup container, @Nullable() Bundle savedInstanceState)
void
onAttach(@NonNull() Context context)
void
onCreate(Bundle savedInstanceState)
void
onResume()
void
onStop()
void
onDestroy()
void
onDetach()
boolean
save()
Saves the annotations in opened document back to Instant Server (PSPDFKit Document Engine). void
saveAsync()
Saves the annotations in opened document back to Instant Server (PSPDFKit Document Engine). InstantPdfDocument
getDocument()
Gets the loaded document. void
onDocumentLoaded(@NonNull() PdfDocument document)
Called when document is successfully loaded and the document view has been laid out. void
syncAnnotations()
Starts syncing annotations back to Instant Server (PSPDFKit Document Engine). void
addInstantDocumentListener(@NonNull() InstantDocumentListener listener)
Adds a InstantDocumentListener for instant document events. void
removeInstantDocumentListener(@NonNull() InstantDocumentListener listener)
Removes a previously added InstantDocumentListener. void
onAuthenticationFailed(@NonNull() InstantPdfDocument instantDocument, @NonNull() InstantException error)
Called when authentication with Instant Server (PSPDFKit Document Engine) has failed. void
onAuthenticationFinished(@NonNull() InstantPdfDocument instantDocument, @NonNull() String validJwt)
Called when authentication with Instant Server (PSPDFKit Document Engine) has successfully finished. void
onSyncStarted(@NonNull() InstantPdfDocument instantDocument)
Called when annotation sync has been started. void
onSyncError(@NonNull() InstantPdfDocument instantDocument, @NonNull() InstantException error)
Called when annotation sync has been finished with an error. void
onSyncFinished(@NonNull() InstantPdfDocument instantDocument)
Called when annotation sync has been finished successfully. void
onDocumentStateChanged(@NonNull() InstantPdfDocument instantDocument, @NonNull() InstantDocumentState state)
Called when the document changes its state. void
onDocumentCorrupted(@NonNull() InstantPdfDocument instantDocument)
Called when InstantPdfDocument has detected data corruption. void
onDocumentInvalidated(@NonNull() InstantPdfDocument instantDocument)
Called when InstantPdfDocument becomes invalid. void
setHandleCriticalInstantErrors(boolean showCriticalErrors)
Sets whether the fragment should automatically handle certain critical Instant errors. UndoManager
getUndoManager()
Returns this fragment's undo manager instance for performing undo/redo operations of annotation edits. void
setOverlaidAnnotationTypes(@NonNull() EnumSet<AnnotationType> overlayAnnotationTypes)
Sets annotation types that should be rendered as overlays. void
setListenToServerChangesWhenVisible(boolean listenToServerChangesWhenVisible)
Controls whether to listen to server changes for loaded document when the fragment is resumed. -
-
Method Detail
-
newInstance
@NonNull() static InstantPdfFragment newInstance(@NonNull() String serverUrl, @NonNull() String jwt, @NonNull() PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document downloaded from Instant Server (PSPDFKit Document Engine).
- Parameters:
serverUrl
- Url of the Instant Server (PSPDFKit Document Engine) - used to initialize InstantClient.jwt
- Authentication token used to authenticate access to the document.configuration
- Configuration for PDF display generated with .- Returns:
New instance of fragment that can be attached to view hierarchy.
-
newInstance
@NonNull() static InstantPdfFragment newInstance(@NonNull() InstantPdfDocument 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.
-
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.
-
onCreateView
@Nullable() View onCreateView(@NonNull() LayoutInflater inflater, @Nullable() ViewGroup container, @Nullable() Bundle savedInstanceState)
-
onResume
void onResume()
-
onStop
void onStop()
-
onDestroy
void onDestroy()
-
onDetach
void onDetach()
-
save
boolean save()
Saves the annotations in opened document back to Instant Server (PSPDFKit Document Engine). Blocks until completed.
-
saveAsync
void saveAsync()
Saves the annotations in opened document back to Instant Server (PSPDFKit Document Engine). Runs on a background thread.
-
getDocument
@Nullable() InstantPdfDocument getDocument()
Gets the loaded document.
- Returns:
Document loaded into the fragment.
-
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.
-
syncAnnotations
void syncAnnotations()
Starts syncing annotations back to Instant Server (PSPDFKit Document Engine).
-
addInstantDocumentListener
void addInstantDocumentListener(@NonNull() InstantDocumentListener listener)
Adds a InstantDocumentListener for instant document events. Listeners added with this method will be removed automatically in onDetach. 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 be notified of instant document events.
-
removeInstantDocumentListener
void removeInstantDocumentListener(@NonNull() InstantDocumentListener listener)
Removes a previously added InstantDocumentListener. After calling this method the
listener
will stop receiving instant 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:
listener
- Listener to unregister from instant document events.
-
onAuthenticationFailed
@UiThread() void onAuthenticationFailed(@NonNull() InstantPdfDocument instantDocument, @NonNull() InstantException error)
Called when authentication with Instant Server (PSPDFKit Document Engine) has failed.
- Parameters:
instantDocument
- Document that we were authenticating for.error
- Authentication error.
-
onAuthenticationFinished
@UiThread() void onAuthenticationFinished(@NonNull() InstantPdfDocument instantDocument, @NonNull() String validJwt)
Called when authentication with Instant Server (PSPDFKit Document Engine) has successfully finished.
- Parameters:
instantDocument
- Document that we were authenticating for.validJwt
- JWT that was used for this authentication request.
-
onSyncStarted
@UiThread() void onSyncStarted(@NonNull() InstantPdfDocument instantDocument)
Called when annotation sync has been started.
- Parameters:
instantDocument
- Document that is syncing the annotations.
-
onSyncError
@UiThread() void onSyncError(@NonNull() InstantPdfDocument instantDocument, @NonNull() InstantException error)
Called when annotation sync has been finished with an error.
The most likely reason is network failure REQUEST_FAILED. Other common reasons are expiration of your authentication token AUTHENTICATION_FAILED, and cancellation USER_CANCELLED.
- Parameters:
instantDocument
- Document that was syncing the annotations.error
- Error thrown while syncing annotations.
-
onSyncFinished
@UiThread() void onSyncFinished(@NonNull() InstantPdfDocument instantDocument)
Called when annotation sync has been finished successfully.
- Parameters:
instantDocument
- Document that was syncing the annotations.
-
onDocumentStateChanged
void onDocumentStateChanged(@NonNull() InstantPdfDocument instantDocument, @NonNull() InstantDocumentState state)
Called when the document changes its state.
Note: After onSyncStarted, this method may be called multiple times during the sync process.
- Parameters:
instantDocument
- Document which state has changed.state
- New document state.
-
onDocumentCorrupted
@UiThread() void onDocumentCorrupted(@NonNull() InstantPdfDocument instantDocument)
Called when InstantPdfDocument has detected data corruption.
Receiving this callback means any further interaction with the sender’s document are destined to fail. You can copy the document package aside for forensic purposes, but you will — eventually — have to purge its storage, and download it anew.
Because this situation means the document has become unusable, it will invalidate itself immediately after this method returns.
- Parameters:
instantDocument
- Document that has detected data corruption.
-
onDocumentInvalidated
@UiThread() void onDocumentInvalidated(@NonNull() InstantPdfDocument instantDocument)
Called when InstantPdfDocument becomes invalid. Any future instant operations on this document will fail.
- Parameters:
instantDocument
- Document that is becoming invalid.
-
setHandleCriticalInstantErrors
void setHandleCriticalInstantErrors(boolean showCriticalErrors)
Sets whether the fragment should automatically handle certain critical Instant errors.
If
true
, when this fragment is visible and a OLD_CLIENT error occurs, an alert will be shown that tells the user the app must be updated. In addition, iftrue
and a OLD_CLIENT or OLD_SERVER error occurs, automatic syncing will be disabled.This defaults to
true
. We recommended that you make your app handle all errors that Instant might encounter, and then set this tofalse
.
-
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.
-
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.
STAMP annotations are always rendered as overlay in Instant that is used to show placeholder while the annotation image data is being downloaded.
- Parameters:
overlayAnnotationTypes
- Annotation types that should be rendered as overlays.
-
setListenToServerChangesWhenVisible
void setListenToServerChangesWhenVisible(boolean listenToServerChangesWhenVisible)
Controls whether to listen to server changes for loaded document when the fragment is resumed.
- Parameters:
listenToServerChangesWhenVisible
-true
to get immediate server updates when fragment is visible.
-
-
-
-