public class

InstantPdfFragment

extends PdfFragment
implements AnnotationProvider.OnAnnotationUpdatedListener InstantDocumentListener
java.lang.Object
   ↳ androidx.fragment.app.Fragment
     ↳ com.pspdfkit.ui.PdfFragment
       ↳ com.pspdfkit.instant.ui.InstantPdfFragment

Class Overview

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.

Summary

Constants
String PARAM_INSTANT_DOCUMENT_SOURCE
[Expand]
Inherited Constants
From class com.pspdfkit.ui.PdfFragment
[Expand]
Inherited Fields
From class com.pspdfkit.ui.PdfFragment
From class androidx.fragment.app.Fragment
Public Constructors
InstantPdfFragment()
Public Methods
void addInstantDocumentListener(InstantDocumentListener listener)
Adds a InstantDocumentListener for instant document events.
AnnotationPreferencesManager getAnnotationPreferences()
Returns manager for annotation preferences.
InstantPdfDocument getDocument()
Gets the loaded document.
UndoManager getUndoManager()
Returns this fragment's undo manager instance for performing undo/redo operations of edits.
static InstantPdfFragment newInstance(InstantPdfDocument document, PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document from an already opened PdfDocument instance.
static InstantPdfFragment newInstance(String serverUrl, String jwt, PdfConfiguration configuration)
Creates and returns a new Fragment to display a PDF document downloaded from instant server.
void onActivityCreated(Bundle savedInstanceState)
void onAnnotationCreated(Annotation annotation)
Called when annotation has been created.
void onAnnotationRemoved(Annotation annotation)
Called when existing annotation has been removed.
void onAnnotationUpdated(Annotation annotation)
Called when existing annotation has changed.
void onAnnotationZOrderChanged(int pageIndex, List<Annotation> oldOrder, List<Annotation> newOrder)
Called when the z-order of annotations has changed on a specified page.
void onAttach(Context context)
void onAuthenticationFailed(InstantPdfDocument instantDocument, InstantException error)
Called when authentication with Instant server has failed.
void onAuthenticationFinished(InstantPdfDocument instantDocument, String validJwt)
Called when authentication with Instant server has successfully finished.
void onCreate(Bundle savedInstanceState)
View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
void onDestroy()
void onDetach()
void onDocumentCorrupted(InstantPdfDocument instantDocument)
Called when InstantPdfDocument has detected data corruption.
void onDocumentInvalidated(InstantPdfDocument instantDocument)
Called when InstantPdfDocument becomes invalid.
void onDocumentLoaded(PdfDocument document)
Called when document is successfully loaded and the document view has been laid out.
void onDocumentStateChanged(InstantPdfDocument instantDocument, InstantDocumentState state)
Called when the document changes its state.
void onResume()
void onStop()
void onSyncError(InstantPdfDocument instantDocument, InstantException error)
Called when annotation sync has been finished with an error.
void onSyncFinished(InstantPdfDocument instantDocument)
Called when annotation sync has been finished successfully.
void onSyncStarted(InstantPdfDocument instantDocument)
Called when annotation sync has been started.
void removeInstantDocumentListener(InstantDocumentListener listener)
Removes a previously added InstantDocumentListener.
void save()
Saves the annotations in opened document back to instant server.
void setHandleCriticalInstantErrors(boolean showCriticalErrors)
Sets whether the fragment should automatically handle certain critical Instant errors.
void setListenToServerChangesWhenVisible(boolean listenToServerChangesWhenVisible)
Controls whether to listen to server changes for loaded document when the fragment is resumed.
void setOverlaidAnnotationTypes(EnumSet<AnnotationType> overlayAnnotationTypes)
Sets annotation types that should be rendered as overlays.
void syncAnnotations()
Starts syncing annotations back to instant server.
Protected Methods
List<Flowable<Double>> getDocumentLoadingProgressObservables()
Gets the list of loading progress observables.
Single<? extends PdfDocument> openDocumentAsync()
For internal usage only.
boolean shouldReloadDocument()
For internal usage only.
[Expand]
Inherited Methods
From class com.pspdfkit.ui.PdfFragment
From class androidx.fragment.app.Fragment
From class java.lang.Object
From interface android.content.ComponentCallbacks
From interface android.view.View.OnCreateContextMenuListener
From interface androidx.activity.result.ActivityResultCaller
From interface androidx.lifecycle.HasDefaultViewModelProviderFactory
From interface androidx.lifecycle.LifecycleOwner
From interface androidx.lifecycle.ViewModelStoreOwner
From interface androidx.savedstate.SavedStateRegistryOwner
From interface com.pspdfkit.annotations.AnnotationProvider.OnAnnotationUpdatedListener
From interface com.pspdfkit.annotations.actions.ActionResolver
From interface com.pspdfkit.instant.listeners.InstantDocumentListener
From interface com.pspdfkit.internal.document.DocumentSaver.DocumentSaveListener
From interface com.pspdfkit.internal.views.document.SpecialModeManager
From interface com.pspdfkit.listeners.DocumentListener
From interface com.pspdfkit.listeners.scrolling.DocumentScrollListener
From interface com.pspdfkit.ui.drawable.PdfDrawableManager
From interface com.pspdfkit.ui.navigation.PageNavigator
From interface com.pspdfkit.ui.special_mode.manager.AnnotationManager
From interface com.pspdfkit.ui.special_mode.manager.AnnotationManager.OnAnnotationDeselectedListener
From interface com.pspdfkit.ui.special_mode.manager.AnnotationManager.OnAnnotationSelectedListener
From interface com.pspdfkit.ui.special_mode.manager.FormManager
From interface com.pspdfkit.ui.special_mode.manager.FormManager.OnFormElementDeselectedListener
From interface com.pspdfkit.ui.special_mode.manager.FormManager.OnFormElementSelectedListener
From interface com.pspdfkit.ui.special_mode.manager.TextSelectionManager

Constants

public static final String PARAM_INSTANT_DOCUMENT_SOURCE

Constant Value: "Instant.InstantDocumentSource"

Public Constructors

public InstantPdfFragment ()

Public Methods

public void addInstantDocumentListener (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. May not be null.

public AnnotationPreferencesManager getAnnotationPreferences ()

Returns manager for annotation preferences.

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

Returns
  • The annotation preferences manager of this fragment.

public InstantPdfDocument getDocument ()

Gets the loaded document.

Returns
  • Document loaded into the fragment.

public UndoManager getUndoManager ()

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

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

public static InstantPdfFragment newInstance (InstantPdfDocument document, PdfConfiguration configuration)

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

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

public static InstantPdfFragment newInstance (String serverUrl, String jwt, PdfConfiguration configuration)

Creates and returns a new Fragment to display a PDF document downloaded from instant server.

Parameters
serverUrl Url of the Instant server - used to initialize InstantClient.
jwt Authentication token used to authenticate access to the document.
configuration Configuration for PDF display generated with PdfConfiguration.Builder.
Returns
  • New instance of fragment that can be attached to view hierarchy.

public void onActivityCreated (Bundle savedInstanceState)

public void onAnnotationCreated (Annotation annotation)

Called when annotation has been created.

Parameters
annotation Annotation that has been created.

public void onAnnotationRemoved (Annotation annotation)

Called when existing annotation has been removed.

Parameters
annotation Annotation that has been removed.

public void onAnnotationUpdated (Annotation annotation)

Called when existing annotation has changed.

Parameters
annotation Annotation that has been changed.

public void onAnnotationZOrderChanged (int pageIndex, List<Annotation> oldOrder, List<Annotation> newOrder)

Called when the z-order of annotations has changed on a specified page.

Parameters
pageIndex Index of the page where the z-order has changed.
oldOrder The old order of annotations on the page.
newOrder The new order of annotations on the page.

public void onAttach (Context context)

public void onAuthenticationFailed (InstantPdfDocument instantDocument, InstantException error)

Called when authentication with Instant server has failed.

Parameters
instantDocument Document that we were authenticating for.
error Authentication error.

public void onAuthenticationFinished (InstantPdfDocument instantDocument, String validJwt)

Called when authentication with Instant server has successfully finished.

Parameters
instantDocument Document that we were authenticating for.
validJwt JWT that was used for this authentication request.

public void onCreate (Bundle savedInstanceState)

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

public void onDestroy ()

public void onDetach ()

public void onDocumentCorrupted (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.

public void onDocumentInvalidated (InstantPdfDocument instantDocument)

Called when InstantPdfDocument becomes invalid. Any future instant operations on this document will fail.

Parameters
instantDocument Document that is becoming invalid.

public void onDocumentLoaded (PdfDocument document)

Called when document is successfully loaded and the document view has been laid out. This has to be called on the main thread.

Parameters
document Loaded document instance.

public void onDocumentStateChanged (InstantPdfDocument instantDocument, InstantDocumentState state)

Called when the document changes its state.

Note: After onSyncStarted(InstantPdfDocument), this method may be called multiple times during the sync process.

Parameters
instantDocument Document which state has changed.
state New document state.

public void onResume ()

public void onStop ()

public void onSyncError (InstantPdfDocument instantDocument, 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.

public void onSyncFinished (InstantPdfDocument instantDocument)

Called when annotation sync has been finished successfully.

Parameters
instantDocument Document that was syncing the annotations.

public void onSyncStarted (InstantPdfDocument instantDocument)

Called when annotation sync has been started.

Parameters
instantDocument Document that is syncing the annotations.

public void removeInstantDocumentListener (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. Passing null is not allowed, and will result in an exception.

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

public void save ()

Saves the annotations in opened document back to instant server.

public 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, if true 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 to false.

public 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. false to disable listening for server changes.

public void setOverlaidAnnotationTypes (EnumSet<AnnotationType> overlayAnnotationTypes)

Sets annotation types that should be rendered as overlays.

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

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.

public void syncAnnotations ()

Starts syncing annotations back to instant server.

Protected Methods

protected List<Flowable<Double>> getDocumentLoadingProgressObservables ()

Gets the list of loading progress observables. These are Flowable Doubles for observing elsewhere. For internal usage only.

protected Single<? extends PdfDocument> openDocumentAsync ()

For internal usage only.

protected boolean shouldReloadDocument ()

For internal usage only.