惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
D
Docker
GbyAI
GbyAI
宝玉的分享
宝玉的分享
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Vercel News
Vercel News
博客园_首页
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
S
SegmentFault 最新的问题
Microsoft Security Blog
Microsoft Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
V
V2EX
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
IT之家
IT之家
Apple Machine Learning Research
Apple Machine Learning Research
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

Inside Nutrient

A guide to the invisible work behind documents Introducing Nutrient Documents for Salesforce: Native document generation and signing Document AI vs. traditional OCR: Choosing between OCR, AI, and hybrid pipelines PDF SDK compliance and security evaluation checklist for enterprise teams (2026) Invariant Corp replaces paper processes with Nutrient Workflow and scales without limits What is process mapping? A complete guide Nutrient vs. Conga Composer for Salesforce document generation (2026) Document routing: How to automate document distribution The CTO’s AI playbook: Why accountability architecture beats orchestration Compliance workflow automation: Why built-in compliance is table stakes Workflow diagrams: Examples, symbols, and how to build one that actually runs Digital forms: Replace paper forms with automated workflows Approval workflow software: How to automate approvals Why document-centric automation is different The CEO’s AI playbook: Why decision architecture beats model selection Nutrient SDK product updates for Q1 2026 PDF redaction verification: How to prove sensitive data is permanently removed What is a VPAT? The complete guide to accessibility conformance reports What is PDF/UA? The accessible PDF standard explained Salesforce eSignatures: Generate, sign, and track documents in one flow Online document viewer: Options, tradeoffs, and how to embed one Document viewer for web apps: React, Vue, Angular (2026) Best document viewers in 2026: A buyer’s guide How to edit a PDF in Python: Add text, images, and annotations Nutrient advances Workflow platform with agentic AI for enterprise-grade speed and consistency in document-heavy operations How to create a Salesforce quote template from opportunity data The business case for accessibility: Five ways it drives enterprise value Python PDF library comparison (2026): 7 libraries for developers Why your AI agent hallucinates PDF table data PDF.js limitations: When to upgrade to a commercial PDF SDK
Jetpack Compose: The ultimate guide
Omar Talaat · 2025-08-05 · via Inside Nutrient

Table of contents

    Jetpack Compose: The ultimate guide

    If you’re using Jetpack Compose and want to integrate Nutrient Android SDK, this post is your all-in-one scrollable spellbook. From setting up the DocumentView inside Compose to handling configuration, lifecycle, gestures, performance tips, real-world use cases, and what’s coming next — it’s all here.

    Jetpack Compose is the future of user interfaces (UIs) in Android. But if you’re wondering how to summon a full-featured document viewer like DocumentView into your modern UI world, you’re not alone. Compose doesn’t (yet) play natively with Views — and that’s where things get interesting.

    Nutrient’s DocumentView is a powerful component built with the Android View system, offering robust PDF rendering, annotations, and much more. While it’s not a Compose-native Composable, it can still shine beautifully with a few tricks.

    Integrate powerful PDF rendering into your Jetpack Compose apps in minutes — no boilerplate, no hassle. Try Nutrient Android SDK and bring your UI to life.

    Setting up your project

    Before diving into code, make sure your project is ready.

    implementation("com.pspdfkit:nutrient-compose:<latest-version>")

    • Make sure you have all permissions and ProGuard rules needed for Nutrient.

    Rendering a PDF with DocumentView

    The hero of this blog post is DocumentView, a UI component that renders PDFs, handles user interaction, and supports gestures and annotations.

    Here’s the simplest way to show a PDF using the Nutrient Compose module:

    DocumentView(

    uri = pdfUri,

    modifier = Modifier.fillMaxSize(),

    configuration = PdfActivityConfiguration.Builder(context)

    .scrollDirection(PageScrollDirection.VERTICAL)

    .build()

    )

    In the code above, you’re using DocumentView, the official Composable from our Android SDK. Modifier.fillMaxSize() tells Compose to make the PDF viewer fill the available space. No manual lifecycle handling, no XML. Just clean, idiomatic Compose.

    Jetpack Compose’s @Preview annotation is one of its standout features, allowing you to see your UI without running the entire app. While this works beautifully for most Composables, DocumentView is a platform view under the hood and may not render correctly in the Android Studio Preview window. To work around this, you can preview the container layout using mock content — such as a placeholder box or image — which mimics the size and position DocumentView would occupy. This helps with layout tuning, theming, and spacing decisions before wiring up the actual PDF viewer.

    Jetpack Compose shines when it comes to live previews. But there’s a catch — you shouldn’t preview DocumentView itself, since it depends on Android runtime resources. Instead, use placeholders:

    @Preview(

    name = "Light Mode",

    showSystemUi = true,

    uiMode = UI_MODE_NIGHT_NO,

    widthDp = 360,

    heightDp = 640

    )

    @Composable

    fun PdfViewerPreview() {

    Box(modifier = Modifier.fillMaxSize()) {

    Text("Preview Mode: PDF would render here")

    }

    }

    Want a dark mode preview?

    @Preview(

    name = "Dark Mode",

    uiMode = UI_MODE_NIGHT_YES

    )

    Check out our theming guide for more information on how to style appearance.

    Use Previews for layout scaffolding and design checks, but leave PDF rendering to the emulator or physical device.

    Styling and layout

    Compose makes it easy to compose rich UIs with Material-inspired components like Card, Box, or Surface, and DocumentView plays nicely with these when it comes to layout and presentation. Wrapping your DocumentView in a Box allows you to apply padding, constraints, or background color. A Card gives you elevation, rounded corners, and visual depth. This is particularly helpful if you’re embedding PDFs in a dashboard-style UI or want to animate visibility using Compose’s animation APIs. You’re not limited to flat, static layouts — you can style, animate, and nest DocumentView just like any other Composable.

    Want a top app bar? Compose makes it simple:

    @Composable

    fun PdfWithTopBar(context: Context, uri: Uri) {

    Scaffold(

    topBar = {

    TopAppBar(title = { Text("My PDF Viewer") })

    }

    ) { paddingValues ->

    DocumentView(

    documentSource = DocumentSource.fromUri(context, uri),

    modifier = Modifier

    .padding(paddingValues)

    .fillMaxSize()

    )

    }

    }

    You can treat DocumentView just like any other Composable. Wrap it in Column, add gestures, or animate its visibility — it plays well with the rest of your Compose UI.

    Interop: XML ↔ Compose

    Still using XML views in parts of your app? No problem. You can embed them like this:

    @Composable

    fun LegacyViewWrapper() {

    AndroidView(

    modifier = Modifier.fillMaxSize(),

    factory = { context ->

    LegacyPdfView(context).apply {

    setDocument("file:///android_asset/sample.pdf")

    }

    }

    )

    }

    This works great for publicly available XML views. But avoid using internal SDK views — they may not behave as expected.

    Managing DocumentView state

    To manage DocumentView state, there are two options, outlined below.

    1. Compose-only using rememberDocumentState(...):

      val documentState = rememberDocumentState(

      uri = pdfUri,

      configuration = PdfActivityConfiguration.Builder(context)

      .scrollDirection(PageScrollDirection.VERTICAL)

      .build()

      )

      DocumentView(documentState = documentState)

    2. ViewModel-driven with manual DocumentState creation:

      val state = DocumentState(

      uri = pdfUri,

      configuration = config

      )

    How to choose between them?

    • If you’re creating simple, self-contained Composables, use rememberDocumentState.

    val state = DocumentState(

    uri = pdfUri,

    configuration = config

    )

    How to choose between them?

    • If you’re creating simple, self-contained Composables, use rememberDocumentState.
    • For production-grade apps, managing state from your ViewModel guarantees your state retention over configuration changes.

    Final thoughts and wrapup

    Jetpack Compose is here to stay — and paired with Nutrient’s SDK, you can build snappy, scalable, and stylish PDF viewers in no time. Integrating the Nutrient SDK into Jetpack Compose is seamless. With DocumentView, you get full PDF rendering power without sacrificing Compose’s flexibility and simplicity.

    Build UI the modern way. Delight users. Make your teammates nod approvingly.

    And if you’re stuck? We’ve got your back. Submit a ticket and we’ll be more than happy to help!

    Ready to integrate powerful PDF rendering into your modern Android UI? Use Nutrient’s Compose module to combine the flexibility of Compose with the robustness of `DocumentView`. Start building today.

    Want to learn more?

    Check out these other blog posts on Jetpack Compose:

    Explore related topics

    Try for free Ready to get started?

    Related SDK articles

    Explore more