Android
ComPDFKit PDF SDK
Guides

Guides                                         

 

If you’re interested in all of the features mentioned in Overview section, please go through our guides to quickly add PDF viewing, annotating, and editing to your application. The following sections list some examples to show you how to add document functionalities to Android apps using our ComPDFKit PDF SDK API.

 

Basic Operations

There are a few commonly used basic operations when working with documents.

Open a Document

Open a local file.

CPDFDocument document = new CPDFDocument(context);
// Open document
CPDFDocument.PDFDocumentError error = document.open(pdfUri);
if (error == CPDFDocument.PDFDocumentError.PDFDocumentErrorPassword) {
 // The document is encrypted and requires a password to open.
 error = document.open(pdfUri, "password");
}
if (error == CPDFDocument.PDFDocumentError.PDFDocumentErrorSuccess) {
 // The document is opened successfully and data can be parsed and manipulated.
} else {
 //The PDF file is failed to open. You can refer to the API file for specific error messages.
}
//Check if the document has been repaired during the opening process.
if (document.hasRepaired()) {
 //The repaired document needs to be saved first and then opened, otherwise any edits or modifications made to the repaired document cannot be saved.
 //Perform a save operation
...
}

 

Note: This is a time-consuming process, so it needs to be executed in a sub-thread. After the document is opened successfully, the UI that renders the PDF is initiated.