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 Xamarin Scanner SDK.
Supported file types
- BMP
- JPG
- JPEG
- PNG
- TIFF
- HEIC
Initialization
Initialize the Docutain Xamarin 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.
- Xamarin.Forms
- Xamarin.Android
- Xamarin.iOS
using Docutain.SDK.Xamarin.Forms;
if(Document.LoadFile(filePath))
{
//generate a PDF from the imported file
var destinationPath = FileSystem.CacheDirectory + "/TestPDF.pdf";
var pdfFile = Document.WritePDF(destinationPath);
if(pdfFile != null)
{
//do something with the generated pdf file
}
else
{
//error occured
var error = DocutainSDK.LastError;
}
}
else
{
//error occured
var error = DocutainSDK.LastError;
}
using Docutain.SDK.Xamarin.Android;
if(Document.LoadFile(filePath))
{
//generate a PDF from the imported file
var destinationPath = FileSystem.CacheDirectory + "/TestPDF.pdf";
var pdfFile = Document.WritePDF(new Java.IO.File(destinationPath));
if(pdfFile != null)
{
//do something with the generated pdf file
}
else
{
//error occured
var error = DocutainSDK.LastError;
}
}
else
{
//error occured
var error = DocutainSDK.LastError;
}
using Docutain.SDK.Xamarin.iOS;
if(Document.LoadFile(fileURL))
{
//generate a PDF from the imported file
var paths = NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User);
var destinationPath = paths[0];
var pdfFile = Document.WritePDF(destinationPath, "TestPDF");
if(pdfFile != null)
{
//do something with the generated pdf file
}
else
{
//error occured
var error = DocutainSDK.LastError;
}
}
else
{
//error occured
var error = DocutainSDK.LastError;
}
If you want to create a searchable PDF (includes text), or get the detected data or text of the imported file, use the DocumentDataReader
class.
- Xamarin.Forms
- Xamarin.Android
- Xamarin.iOS
using Docutain.SDK.Xamarin.Forms;
if(DocumentDataReader.LoadFile(filePath))
{
//generate a searchable PDF from the imported file
var destinationPath = FileSystem.CacheDirectory + "/TestPDF.pdf";
var pdfFile = Document.WritePDF(destinationPath);
//get the detected text
var text = DocumentDataReader.GetText();
//get the detected data
var data = DocumentDataReader.Analyze();
}
else
{
//error occured
var error = DocutainSDK.LastError;
}
using Docutain.SDK.Xamarin.Android;
if(DocumentDataReader.LoadFile(filePath))
{
//generate a searchable PDF from the imported file
var destinationPath = FileSystem.CacheDirectory + "/TestPDF.pdf";
var pdfFile = Document.WritePDF(new Java.IO.File(destinationPath));
//get the detected text
var text = DocumentDataReader.GetText();
//get the detected data
var data = DocumentDataReader.Analyze();
}
else
{
//error occured
var error = DocutainSDK.LastError;
}
using Docutain.SDK.Xamarin.iOS;
if(DocumentDataReader.LoadFile(fileURL))
{
//generate a searchable PDF from the imported file
var paths = NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User);
var destinationPath = paths[0];
var pdfFile = Document.WritePDF(destinationPath, "TestPDF");
//get the detected text
var text = DocumentDataReader.GetText();
//get the detected data
var data = DocumentDataReader.Analyze();
}
else
{
//error occured
var error = DocutainSDK.LastError;
}