Prevent sharing of PDF files on Android
Nutrient Android SDK 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.
ShareFeatures controls sharing everywhere it’s offered. That covers the main toolbar’s share item and its sharing menu, the text selection popup, the annotation popup, and the annotation note editor. Disabling the features is therefore the reliable way to prevent sharing.
If you only want to remove the share item from the main toolbar and keep sharing available elsewhere, hide it with a ToolbarItemsProvider:
class CustomActivity : PdfActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setToolbarItemsProvider { defaultItems -> defaultItems.filter { it.id != PdfActivity.MENU_OPTION_SHARE } } }}public class CustomActivity extends PdfActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setToolbarItemsProvider(defaultItems -> { final List<ToolbarItem> items = new ArrayList<>(defaultItems); items.removeIf(item -> item.getId() == PdfActivity.MENU_OPTION_SHARE); return items; }); }}The sharing menu behind the share item also offers Open, Print, and Save As…, and removing the item removes all of them from the toolbar. Printing is disabled separately with printingEnabled(false).
More information on menu customization, such as menu options other than sharing, can be found in our guide on customizing the main toolbar.