Building an Activity around the PdfFragment
You might want to customize the user interface of your app beyond what is possible with the predefined UI of the
PdfActivity. The greatest flexibility can be achieved by embedding the
PdfFragment into a custom
AppCompatActivity. This guide provides the foundation for using the fragment in a custom environment in conjunction with existing PSPDFKit widgets that are also used by the
ℹ️ Note: This article describes how to manually build a custom activity that uses the
PdfFragmentand other framework widgets. The other, simpler solutions are to either extend the existing
PdfActivityor load a document into the default
PdfActivity. You can also use the
PdfUiFragmentto display the document with the same UI the
PdfActivityuses. To see how, please refer to the Using a Fragment guide.
Embedding the Fragment
Take a look at our Using a Fragment guide, which shows the basics of setting up the
PdfFragment by providing a license and configuration. A runnable code example can be found inside our Catalog app: The
FragmentExample showcases how to use the
PdfFragment in a custom
PSPDFKit has two predefined search widgets that are also used by the
PdfSearchViewInlineis a small search widget that, when expanded, sits inside the main action bar. It provides an input field, a results label showing the number of found results, and controls for navigating back and forth inside the results. This widget is useful on smaller devices, where a list of all results would overlay the viewed document.
PdfSearchViewModularis an expandable panel that sits above the document area. It shows a full scrollable list of all results, including preview snippets. Tapping a result will close the search view and navigate to the page containing the result.
ℹ️ Note: As a third option, you can manually build a custom search widget using our extensive search API.
You can use all the PSPDFKit toolbars as standalone views in your custom activities. Have a look at the Using Toolbars within Fragment guide for more information.