public class

PdfUiFragment

extends Fragment
implements PdfUi
java.lang.Object
   ↳ androidx.fragment.app.Fragment
     ↳ com.pspdfkit.ui.PdfUiFragment

Class Overview

Experimental API - Might change in the future.

This fragment provides the same UI as PdfActivity. It can be used inside any view hierarchy but use is limited to one instance per Activity, unless pdfFragmentTag(String) is used to set a unique fragment tag for each instance.

Summary

[Expand]
Inherited Constants
From interface com.pspdfkit.ui.PdfUi
[Expand]
Inherited Fields
From class androidx.fragment.app.Fragment
Public Constructors
PdfUiFragment()
Public Methods
PdfActivityConfiguration getConfiguration()
Returns the PdfActivityConfiguration that was provided while launching this pdf UI.
void onActivityResult(int requestCode, int resultCode, Intent data)
boolean onBackPressed()
Call this from your activity to properly close the UI when pressing back.
void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
void onDestroy()
boolean onDocumentClick()
Called when the user taps / clicks on the document, not the page itself but on the side (if visible).
void onDocumentLoadFailed(Throwable exception)
Called if document loading has failed.
void onDocumentLoaded(PdfDocument document)
Called when document is successfully loaded and the document view has been laid out.
boolean onDocumentSave(PdfDocument document, DocumentSaveOptions saveOptions)
Called before document will be saved.
void onDocumentSaveCancelled(PdfDocument document)
Called if document saving has been cancelled.
void onDocumentSaveFailed(PdfDocument document, Throwable exception)
Called if document saving has failed.
void onDocumentSaved(PdfDocument document)
Called after the document has been saved.
void onDocumentZoomed(PdfDocument document, int pageIndex, float scaleFactor)
Called when a user zooms a document.
List<Integer> onGenerateMenuItemIds(List<Integer> menuItems)
int onGetShowAsAction(int menuItemId, int defaultShowAsAction)
boolean onOptionsItemSelected(MenuItem item)
void onPageChanged(PdfDocument document, int pageIndex)
Called when user scrolled to a new page.
boolean onPageClick(PdfDocument document, int pageIndex, MotionEvent event, PointF pagePosition, Annotation clickedAnnotation)
Called when user taps / clicks on the page.
void onPageUpdated(PdfDocument document, int pageIndex)
Called when content of page with pageIndex has changed (for example due to annotation or form field being updated).
void onPause()
void onPrepareOptionsMenu(Menu menu)
void onResume()
void onSaveInstanceState(Bundle outState)
void onSetActivityTitle(PdfActivityConfiguration configuration, PdfDocument document)
Called when activity title must be set - before and after document was loaded.
void onStart()
void onStop()
void onUserInterfaceVisibilityChanged(boolean visible)
Called when user interface visibility have changed.
void setConfiguration(PdfActivityConfiguration configuration)
Replaces activity configuration.
[Expand]
Inherited Methods
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.internal.ui.menu.PdfActivityMenu.OnMenuItemsGenerateListener
From interface com.pspdfkit.internal.ui.menu.PdfActivityMenu.OnPrepareDefaultMenuItemListener
From interface com.pspdfkit.listeners.DocumentListener
From interface com.pspdfkit.listeners.PdfActivityListener
From interface com.pspdfkit.ui.PdfUi

Public Constructors

public PdfUiFragment ()

Public Methods

public PdfActivityConfiguration getConfiguration ()

Returns the PdfActivityConfiguration that was provided while launching this pdf UI.

Returns
  • Currently set activity configuration.

public void onActivityResult (int requestCode, int resultCode, Intent data)

public boolean onBackPressed ()

Call this from your activity to properly close the UI when pressing back.

Returns
  • This method returns true if the event was consumed and should not be processed any further.

public void onCreateOptionsMenu (Menu menu, MenuInflater inflater)

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

public void onDestroy ()

public 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 or false if PSPDFKit should execute it's default action.

public void onDocumentLoadFailed (Throwable exception)

Called if document loading has failed.

Parameters
exception Cause of the loading failure.

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 boolean onDocumentSave (PdfDocument document, 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. You may change parameters on this object to control how document is saved.
Returns
  • true if the document should be saved, false if saving should be cancelled.

public void onDocumentSaveCancelled (PdfDocument document)

Called if document saving has been cancelled.

Parameters
document Instance of document that was saved.

public void onDocumentSaveFailed (PdfDocument document, Throwable exception)

Called if document saving has failed.

Parameters
exception Cause of the saving failure if applicable.

public void onDocumentSaved (PdfDocument document)

Called after the document has been saved.

Parameters
document Instance of document that was saved.

public void onDocumentZoomed (PdfDocument document, 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.

public List<Integer> onGenerateMenuItemIds (List<Integer> menuItems)

public int onGetShowAsAction (int menuItemId, int defaultShowAsAction)

public boolean onOptionsItemSelected (MenuItem item)

public void onPageChanged (PdfDocument document, int pageIndex)

Called when user scrolled to a new page.

Parameters
document Currently opened document.
pageIndex Page number of new page.

public boolean onPageClick (PdfDocument document, int pageIndex, MotionEvent event, PointF pagePosition, 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. May be null if this page click was triggered from keyboard or accessibility event.
pagePosition Tapped page position (in PDF page coordinates with origin on bottom left). Coordinates passed here may exceed the page size (which is returned by getPageSize(int)) and can also be negative. If the click was triggered by the keyboard, pagePosition will be null.
clickedAnnotation Annotation that was tapped, or null if no annotation was tapped.
Returns
  • true if tap was handled by this DocumentListener and should not be handled by PSPDFKit anymore. If returning false PSPDFKit will continue executing it's default action.

public void onPageUpdated (PdfDocument document, 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. Page index is 0-based.

public void onPause ()

public void onPrepareOptionsMenu (Menu menu)

public void onResume ()

public void onSaveInstanceState (Bundle outState)

public void onSetActivityTitle (PdfActivityConfiguration configuration, PdfDocument document)

Called when activity title must be set - before and after document was loaded.

Parameters
configuration Passed activity configuration instance.
document Loaded document. If document hasn't been loaded yet, this parameter will be null.

public void onStart ()

public void onStop ()

public void onUserInterfaceVisibilityChanged (boolean visible)

Called when user interface visibility have changed.

Parameters
visible true when UI interface is visible, false when it is hidden.

public void setConfiguration (PdfActivityConfiguration configuration)

Replaces activity configuration. This method restarts the pdf UI to apply new configuration.

Note: This is a no-op when configuration has not changed.

Parameters
configuration The configuration to restart pdf UI with.