Jetpack Compose and DocumentView Q&A
This guide answers some questions you might face when using Jetpack Compose with Nutrient Android SDK.
Hiding page numbers
Q: How can I make the page numeration label vanish when a page is changed?
A: You can rely on the hidePageNumberOverlay
option for that!
Summoning page overviews
Q: How do I show page overviews programmatically?
A: This is possible with the toggleView
function.
With toggle view, you can switch to any view, like search, outline, document info, etc.
The page overview is PdfThumbnailGrid
, which can be displayed dynamically using the toggleView
function from documentState
, as seen in documentState.toggleView(PdfActivity.MENU_OPTION_THUMBNAIL_GRID)
.
Creating dynamic annotations with Compose
Q: Can I dynamically add annotations using Jetpack Compose, similar to the Fragment examples?
A: The DocumentState
has a reference to documentConnectionof
of type DocumentConnection
that provides this method to addAnnotationToPage
. Under the hood, this calls PdfFragment.addAnnotationToPage
.
Opening AES-encrypted PDFs
Q: How can I open an AES-encrypted PDF using Jetpack Compose?
A: Ideally, the PDF should open the pdfActivity
from a Compose callback. However, our current Compose DocumentView
doesn’t yet support providers as an input. As a result, this has been categorized as a feature request. While we cannot guarantee if and when these changes will be implemented, we carefully consider all requests that are submitted.
Moreover, if you wish to avoid using PdfActivity
, you’ll need to decrypt the PDF on your own and pass the URL in our Compose document view. The code provided in the Compose callback should be effective for your needs:
val provider = AesDataProvider( documentFile.absolutePath, AesEncryptedFileExample.BASE64_ENCRYPTION_KEY) val intent = PdfActivityIntentBuilder.fromDataProvider(context, provider) .configuration(pdfActivityConfiguration) .build() context.startActivity(intent)
-
Moreover, it’s possible to use your own decryption and pass it to Compose
DocumentView
.
Nesting DocumentView
Q: Can I make DocumentView
work as part of a larger Compose UI, taking up just a portion of the screen?
A: Yes! Consider the following code:
Column { DocumentView( documentState = documentState, modifier = Modifier .fillMaxWidth() .weight(0.33F, true), ) Box( modifier = Modifier .fillMaxWidth() .weight(0.67F, true) ) { // The remaining 2/3 of your mystical UI. } }
Conclusion
Nutrient offers many more customization options and features. We’re always aiming to expand these examples to the best of our capabilities. For comprehensive information about implementing and customizing Nutrient in your Android app, refer to our extensive documentation, or contact our Support team for personalized assistance.