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.

    • Constructor Detail

      • InstantPdfFragment

        InstantPdfFragment()
    • 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.

      • 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.

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

        Parameters:
        listener - Listener to unregister from instant document events.
      • 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.
      • 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.
      • 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, 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.

      • 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.