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 iOS Scanner SDK.
Supported file types
- BMP
- JPG
- JPEG
- PNG
- TIFF
- HEIC
- WebP
Initialization
- Follow the Getting started guide
- Initialize the Docutain iOS Scanner SDK as described here
File Import
Depending on what you want to achieve, you either need to use the Document class or the DocumentDataReader class.
If your simple goal is to import image files and generate a (non-searchable) PDF file from it, use the Document class. For everything else, use the DocumentDataReader class.
Load an image file and generate a non-searchable PDF:
import DocutainSdk
if(Document.loadFile(fileUrl: url)){
if let pdfUrl = Document.writePDF(fileUrl: path, fileName: "Test"){
//do something with the generated pdf file
} else{
//error occured
let error = DocutainSDK.getLastError()
}
} else{
//error occured
let error = DocutainSDK.getLastError()
}
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.
import DocutainSdk
if(DocumentDataReader.loadFile(fileUrl: url)){
let text = DocumentDataReader.getText()
let documentData = DocumentDataReader.analyze()
if let pdfUrl = Document.writePDF(fileUrl: path, fileName: "Test"){
//do something with the generated pdf file
} else{
//error occured
let error = DocutainSDK.getLastError()
let errorCode = DocutainSDK.getLastErrorCode()
if(errorCode == .passwordNotValid){
//the file is encrypted and no password or the wrong password was entered
//you can provide the password in the DocumentDataReader.loadFile() method.
}
}
} else{
//error occured
let error = DocutainSDK.getLastError()
}
Load from memory
If the file is already available as Data, e.g. when it was received from a server, you can load it directly without writing a temporary file first. Provide the file extension so Docutain knows the file type.
Document supports images (JPG, PNG, BMP, HEIC, WebP, TIFF).
import DocutainSdk
if(Document.loadFile(data: imageData, fileExtension: "jpg")){
//document loaded
} else{
//error occurred
let error = DocutainSDK.getLastError()
}
To load a PDF from memory, use the DocumentDataReader class. It supports the same image formats as well. If the PDF file is password-protected, you can provide the password.
import DocutainSdk
if(DocumentDataReader.loadFile(data: pdfData, fileExtension: "pdf", password: "password")){
let text = DocumentDataReader.getText()
let documentData = DocumentDataReader.analyze()
} else{
//error occurred
let error = DocutainSDK.getLastError()
}
Add pages
To add further pages to the currently loaded document, use addPageFile(fileUrl:) with a file or addPage(data:fileExtension:) with Data.
import DocutainSdk
if(Document.loadFile(fileUrl: url)){
Document.addPageFile(fileUrl: secondUrl)
Document.addPage(data: imageData, fileExtension: "jpg")
}
DocumentDataReader provides addPageFile(fileUrl:) as well.
Pages can only be added from images, not from PDFs.
All of these methods return false if the data is invalid, the file type is not supported or the file doesn't exist.