Skip to content

Simple and easy to use Android PDF Viewer library. Made with and for Jetpack Compose. PDFs from Raw Resources, URIs and URLs are supported.

License

Notifications You must be signed in to change notification settings

arcanegolem/Lycoris

Repository files navigation

Lycoris

Lycoris Header Lycoris is an effortless PDF viewing library which provides ready-to-use PDF viewing composables fully made with and for Jetpack Compose. Depends on Retrofit2, Coil and Material Icons. Supports PDF from Raw resources, Uri and URL.

Contents

DEMO

This can be achieved with following code (Sample in MainActivity):

// ...
Column (
  modifier = Modifier.fillMaxSize()
) {
  PdfViewer (
    pdfResId = R.raw.sample_multipage,
    controlsAlignment = Alignment.CenterEnd,
  )
}
// ...

NEW(!)

PdfViewer

  • Now has zoom controls instead of separate dialogs for each page
  • Added iconTint and accentColor for zoom controls (NOTE: accentColor will apply with 40% alpha)
  • Added controlsAlignment parameter for zoom controls positioning inside PdfViewer's box
  • Added bitmapScale for upscaling/downscaling pages for better readability/performance
  • Added support for documents with unordinary aspect ratios

HorizontalPagerPdfViewer

  • Now marked Experimental
  • Is unstable and unmaintained for now

VerticalPagerPdfViewer

  • Now marked Experimental
  • Is unstable and unmaintained for now

Requirements

  • Add INTERNET permission to your Android Manifest
<uses-permission android:name="android.permission.INTERNET" />
  • [OPTIONAL] Set android:usesCleartextTraffic="true" in your Android Manifest <application> tag to enable downloading of PDF documents from unsecure http:// URLs
<application>
  ...
  android:usesCleartextTraffic="true"
  ...
</application>
  • Add Jitpack to your project repositories
dependencyResolutionManagement {
  repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
  repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
  }
}
  • Add lycoris to your project dependencies
dependencies {
  implementation 'com.github.arcanegolem:Lycoris:1.0.0-alpha01'
}

Usage

Module contains overloaded PdfViewer, HorizontalPagerPdfViewer and VerticalPagerPdfViewer ready-to-use composable functions, usage examples below:

WARNING: PdfViewer function utilizes LazyColumn composable.

PDF from Raw Resource

PdfViewer (
   modifier: Modifier = Modifier,
   @RawRes pdfResId: Int,
   pagesVerticalArrangement: Arrangement.Vertical = Arrangement.spacedBy(8.dp),
   iconTint : Color = Color.Black,
   accentColor : Color = Color.DarkGray,
   controlsAlignment: Alignment = Alignment.BottomEnd,
   bitmapScale : Int = 1
)

VerticalPagerPdfViewer (
   modifier: Modifier = Modifier,
   @RawRes pdfResId: Int,
   documentDescription : String
)

HorizontalPagerPdfViewer(
   modifier: Modifier = Modifier,
   @RawRes pdfResId: Int,
   documentDescription : String
)

PDF from Uri

PdfViewer (
   modifier: Modifier = Modifier,
   uri: Uri,
   pagesVerticalArrangement: Arrangement.Vertical = Arrangement.spacedBy(8.dp),
   accentColor: Color = Color.DarkGray,
   iconTint: Color = Color.Black,
   controlsAlignment: Alignment = Alignment.BottomEnd,
   bitmapScale : Int = 1
)

VerticalPagerPdfViewer(
   modifier: Modifier = Modifier,
   uri: Uri
)

HorizontalPagerPdfViewer(
   modifier: Modifier = Modifier,
   uri: Uri
)

PDF from URL

PdfViewer(
   modifier: Modifier = Modifier,
   @Url url: String,
   headers: HashMap<String, String>? = null,
   pagesVerticalArrangement: Arrangement.Vertical = Arrangement.spacedBy(8.dp),
   accentColor: Color = Color.DarkGray,
   iconTint: Color = Color.Black,
   controlsAlignment: Alignment = Alignment.BottomEnd,
   bitmapScale : Int = 1
)

VerticalPagerPdfViewer(
   modifier: Modifier = Modifier,
   @Url url: String
   headers: HashMap<String, String>,
)

HorizontalPagerPdfViewer(
   modifier: Modifier = Modifier,
   @Url url: String,
   headers: HashMap<String, String>
)

Thanks to