Skip to main content

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.

Android PDF Creation

Android Text Detection

Android Data Extraction

Supported file types

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

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.
}

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.

info

Set android.enableJetifier=true in your gradle.properties file.

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.
}
info

You can also load a file from a ByteArray or an absolute Path.

caution

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.

Data and file storage overview

Permission handling