File Import
You can import images or PDF files into Docutain and do a bunch of things with them, same as after a successful document scan with Docutain's Android Scanner SDK.
Supported file types
- BMP
- JPG
- JPEG
- PNG
- TIFF
- HEIC
Initialization
Define dependencies depending on your purchased license and usecase in your app's build.gradle
file:
def docutainSdkVersion = '1.7.0.3'
//For Document Scanner components
implementation("de.docutain:Docutain-SDK-UI:$docutainSdkVersion")
//For Data Extraction and OCR (Text Recognition) components
implementation("de.docutain:Docutain-SDK-DataExtraction:$docutainSdkVersion")
Initialize the Docutain Android SDK as described here.
File Import
If your simple goal is to import image files and generate a non-searchable (includes no text) PDF file from it, use the Document
class.
- Kotlin
- Java
try{
if(Document.loadFile(uri)) {
val pdfFile = Document.writePDF(File(filesDir, "testPDF"))
if(pdfFile != null){
//do something with the generated pdf file
} else{
//error occured
val error = DocutainSDK.getLastError()
}
} else{
//error occured
val error = DocutainSDK.getLastError()
}
}catch(ex : SecurityException){
//SecurityException is thrown if the file is encrypted and no password or the wrong password was entered
//you can provide the password in the Document.loadFile() method.
}
try{
if(Document.loadFile(uri)) {
File pdfFile = Document.writePDF(new File(getFilesDir(), "testPDF"));
if(pdfFile != null){
//do something with the generated pdf file
} else{
//error occured
String error = DocutainSDK.getLastError();
}
} else{
//error occured
String error = DocutainSDK.getLastError();
}
}catch(SecurityException ex){
//SecurityException is thrown if the file is encrypted and no password or the wrong password was entered
//you can provide the password in the Document.loadFile() method.
}
If you want to create searchable (including text) PDF files, or get the text of the loaded document or get the analyzed data from it, you need to use the DocumentDataReader
class.
Set android.enableJetifier=true
in your gradle.properties
file.
- Kotlin
- Java
try{
if(DocumentDataReader.loadFile(uri)) {
val text = DocumentDataReader.getText()
val documentData = DocumentDataReader.analyze()
val pdfFile = Document.writePDF(File(filesDir, "testPDF"))
if(pdfFile != null){
//do something with the generated pdf file
} else{
//error occured
val error = DocutainSDK.getLastError()
}
} else{
//error occured
val error = DocutainSDK.getLastError()
}
}catch(ex : SecurityException){
//SecurityException is thrown if the file is encrypted and no password or the wrong password was entered
//you can provide the password in the DocumentDataReader.loadFile() method.
}
try{
if(DocumentDataReader.loadFile(uri)) {
String text = DocumentDataReader.getText();
String documentData = DocumentDataReader.analyze();
File pdfFile = Document.writePDF(new File(getFilesDir(), "testPDF"));
if(pdfFile != null){
//do something with the generated pdf file
} else{
//error occured
String error = DocutainSDK.getLastError();
}
} else{
//error occured
String error = DocutainSDK.getLastError();
}
}catch(SecurityException ex){
//SecurityException is thrown if the file is encrypted and no password or the wrong password was entered
//you can provide the password in the DocumentDataReader.loadFile() method.
}
You can also load a file from a ByteArray
or an absolute Path
.
If the path points to a file that does not belong to your app's internal folder, you are responsible for checking and requesting permission to access this file.