Prevent Sharing of PDF Files on Android

PSPDFKit for Android enables you to customize the document sharing experience. To prevent your end users from sharing documents, you can either remove the default menu action, or use the setEnabledShareFeatures option when building your PdfActivityConfiguration.

The latter option is the simplest:

configuration = PdfActivityConfiguration.Builder(configuration)
    .setEnabledShareFeatures(ShareFeatures.none())
    .build()
PdfActivityConfiguration configuration = configBuilder
    .setEnabledShareFeatures(ShareFeatures.none())
    .build();

Note that setEnabledShareFeatures uses the ShareFeatures enum, providing you with a granular approach if needed.

For even more control over the menus, the following snippet shows you how to remove sharing options during menu generation:

class CustomActivity : PdfActivity() {
    override fun onGenerateMenuItemIds(menuItems: MutableList<Int>): List<Int> {
        // Take the default menu item IDs and remove the outlined items.
        menuItems.remove(PdfActivity.MENU_OPTION_SHARE)

        // Return the new order for the menu items.
        return menuItems
    }
}
public class CustomActivity extends PdfActivity {
    @Override
    public List<Integer> onGenerateMenuItemIds(@NonNull List<Integer> menuItems) {
        // Take the default menu item IDs and remove the outlined items.
        menuItems.remove(PdfActivity.MENU_OPTION_SHARE);

        // Return the new order for the menu items.
        return menuItems;
    }
}

More information on menu customization, such as menu options other than sharing, can be found in our guide on customizing the main toolbar.