Guides
Using CPDFReaderView
The ComPDF SDK provides the CPDFReaderView component for viewing and editing PDF documents in Android applications. This section describes how to add this view to a layout and initialize it.
- Add
CPDFReaderViewto the XML layout
xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- Create a CPDFReaderView -->
<com.compdfkit.ui.reader.CPDFReaderView
android:id="@+id/readerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>- Obtain and initialize the view in code
java
// Get CPDFReaderView from XML
CPDFReaderView readerView = findViewById(R.id.readerview);- Open a PDF document
java
CPDFDocument document = new CPDFDocument(context);
PDFDocumentError error = document.open("filePath"); // file path or uri
if (error == PDFDocumentError.PDFDocumentErrorSuccess){
// Bind the document to CPDFReaderView
readerView.setPDFDocument(document);
}