PDF Creation
The Docutain SDK for Capacitor comes with the ability to create searchable PDF documents either from a scanned document with Docutain's Scanner SDK or imported file.
Initialization
Initialize the Docutain Capacitor SDK as described here.
Create a PDF
import { DocutainSDK, PDFPageFormat } from '@docutain/capacitor-plugin-docutain-sdk'
//...
//scan or import file
//...
try{
var destinationUri = (await Filesystem.getUri({ path: "sample.pdf", directory:Directory.Data })).uri;
const pdfUri = (await DocutainSDK.writePDF({
fileUri: destinationUri,
overWrite: true,
})).fileUri
} catch (error) {
console.error(error);
}
You can specify to overwrite an existing file and the PDF page format by providing the appropriate value.
PDF Page Format
You can specify the PDF page format by providing the appropriate value:
const pdfUri = (await DocutainSDK.writePDF({
fileUri: destinationUri,
pageFormat: PDFPageFormat.A4
})).fileUri
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:
const pdfUri = (await DocutainSDK.writePDF({
fileUri: destinationUri,
maxSizeKB: 10240
})).fileUri