Open password-protected PDFs on Android
PDF documents support passwords and other security methods. Nutrient can write annotations and forms to password-protected documents when their permissions enable editing.
Some protected documents use an empty password. Nutrient tries an empty password before displaying the password dialog, matching Adobe Acrobat’s behavior.
Password dialog
Nutrient Android SDK prompts users for a password when opening a protected PDF that requires one, so you don’t need additional setup.
Supplying passwords programmatically
To open a protected PDF without a prompt, supply its password through PdfActivityIntentBuilder’s passwords method:
val fileUri = Uri.parse("file:///path/to/your/document.pdf")val intent = PdfActivityIntentBuilder.fromUri(context, fileUri) .passwords("file_password_goes_here") .build()context.startActivity(intent)final Uri fileUri = Uri.parse("file:///path/to/your/document.pdf");final Intent intent = PdfActivityIntentBuilder.fromUri(context, fileUri) .passwords("file_password_goes_here") .build();context.startActivity(intent);For PdfUiFragment instead of PdfActivity, supply the password through PdfUiFragmentBuilder:
val fileUri = Uri.parse("file:///path/to/your/document.pdf")val fragment = PdfUiFragmentBuilder.fromUri(context, fileUri) .passwords("file_password_goes_here") .build()supportFragmentManager.beginTransaction() .replace(R.id.fragmentContainer, fragment) .commit()final Uri fileUri = Uri.parse("file:///path/to/your/document.pdf");final PdfUiFragment fragment = PdfUiFragmentBuilder.fromUri(context, fileUri) .passwords("file_password_goes_here") .build();getSupportFragmentManager().beginTransaction() .replace(R.id.fragmentContainer, fragment) .commit();For PdfFragment, use a newInstance overload that accepts a list of document passwords:
val fileUri = Uri.parse("file:///path/to/your/document.pdf")val fragment = PdfFragment.newInstance( listOf(fileUri), listOf("file_password_goes_here"), configurationBuilder.build())final Uri fileUri = Uri.parse("file:///path/to/your/document.pdf");final PdfFragment fragment = PdfFragment.newInstance( Collections.singletonList(fileUri), Collections.singletonList("file_password_goes_here"), configurationBuilder.build());