mklkj / Lycoris

Android PDF viewing library for Jetpack Compose

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lycoris

Lycoris Header Lycoris is an effortless PDF viewing library fully made with Jetpack Compose. Depends on Retrofit2 and Coil.

Contents

NEW

  • HorizontalPagerPdfViewer
  • VerticalPagerPdfViewer

Requirements

NOTE: Library is not yet published anywhere, so you need to clone this repo and import lycoris module in order to use it.

  • 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>

Usage

Module contains overloaded PdfViewer, HorizontalPagerPdfViewer and VerticalPagerPdfViewer composable functions, usage examples below:

WARNING: PdfViewer function utilizes LazyColumn composable.

Retrieving PDF document via raw resource:

//============== Parameters ================
fun PdfViewer(
   modifier: Modifier = Modifier.fillMaxSize(),
   @RawRes pdfResId: Int,
   documentDescription: String,
   verticalArrangement: Arrangement.Vertical = Arrangement.spacedBy(8.dp)
)

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

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

//================ Usage ===================
PdfViewer(
  pdfResId = R.raw.sample_pdf, 
  documentDescription = "sample description",
)

HorizontalPagerPdfViewer(
  pdfResId = R.raw.sample_pdf, 
  documentDescription = "sample description",
)

VerticalPagerPdfViewer(
  pdfResId = R.raw.sample_pdf, 
  documentDescription = "sample description",
)

Retriving PDF document via URI:

//============== Parameters ================
fun PdfViewer(
   modifier: Modifier = Modifier.fillMaxSize(),
   uri: Uri,
   verticalArrangement: Arrangement.Vertical = Arrangement.spacedBy(8.dp)
)

fun HorizontalPagerPdfViewer(
   modifier: Modifier = Modifier.fillMaxWidth(),
   uri: Uri,
)

fun VerticalPagerPdfViewer(
   modifier: Modifier = Modifier.fillMaxWidth(),
   uri: Uri,
)

//================ Usage ===================
PdfViewer(
  uri = // Your URI
)

HorizontalPagerPdfViewer(
  uri = // Your URI
)

VerticalPagerPdfViewer(
  uri = // Your URI
)

Retriving PDF document via URL:

//============== Parameters ================
fun PdfViewer(
   modifier: Modifier = Modifier.fillMaxSize(),
   @Url url: String,
   headers: HashMap<String, String>,
   verticalArrangement: Arrangement.Vertical = Arrangement.spacedBy(8.dp)
)

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

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

//================ Usage ===================
PdfViewer(
  url = "https://sample.link.com/sample_pdf.pdf",
  headers = hashMapOf( "headerKey" to "headerValue" )
)

HorizontalPagerPdfViewer(
  url = "https://sample.link.com/sample_pdf.pdf",
  headers = hashMapOf( "headerKey" to "headerValue" )
)

VerticalPagerPdfViewer(
  url = "https://sample.link.com/sample_pdf.pdf",
  headers = hashMapOf( "headerKey" to "headerValue" )
)

Known issues

  • Occasional slow load of PDF documents retrieved via URL in PdfViewer

About

Android PDF viewing library for Jetpack Compose


Languages

Language:Kotlin 100.0%