PDF Creation
The Docutain SDK for Android comes with the ability to create searchable and non-searchable PDF documents either from a scanned document with Docutain's Scanner SDK or imported file.
Initialization
Initialize Docutain's Android SDK as described here.
Create a PDF
In order to create a PDF document, first a document needs to be scanned with Docutain's Scanner SDK or imported.
After that you can generate the PDF document.
Generating the PDF is blazingly fast, but it may still take some time depending on the number of pages and the performance of the device. To avoid blocking the UI thread, we recommend running the PDF creation in a background thread.
- Kotlin
- Java
import de.docutain.sdk.Document
...
//scan or import file
...
val pdfFile = Document.writePDF(File(filesDir, "testPDF"))
if(pdfFile != null){
//do something with the created PDF file
} else{
//error occured
val error = DocutainSDK.getLastError()
}
import de.docutain.sdk.Document
...
//scan or import file
...
File pdfFile = Document.writePDF(new File(getFilesDir(), "testPDF"));
if(pdfFile != null){
//do something with the created PDF file
} else{
//error occured
String error = DocutainSDK.getLastError();
}
PDF Page Format
You can specify the PDF page format by providing the appropriate value:
- Kotlin
- Java
val pdfFile = Document.writePDF(File(filesDir, "testPDF"), true, Document.PDFPageFormat.A4)
File pdfFile = Document.writePDF(new File(getFilesDir(), "testPDF"), true, Document.PDFPageFormat.A4);
PDF Compression
You can specify a maximum file size for the PDF. If the uncompressed PDF would exceed the maximum file size you have set, it will get compressed until the maximum file size is reached. Please be aware, that if the PDF gets compressed, the quality decreases and the PDF generation will take longer. In order to set a maximum file size, set the maxSizeKB
parameter to your desired size. It needs to be set in KB, so if you want 10MB for example, set it to 10 * 1024. Please check below example:
- Kotlin
- Java
val pdfFile = Document.writePDF(File(filesDir, "testPDF"), true, Document.PDFPageFormat.A4, 10*1024)
File pdfFile = Document.writePDF(new File(getFilesDir(), "testPDF"), true, Document.PDFPageFormat.A4, 10*1024);