importDocument method
Imports another PDF document and inserts it at a specified position in the current document.
This method imports an external PDF document into the current document, allowing you to choose which pages to import and where to insert the document.
Example:
final filePath = '/data/user/0/com.compdfkit.flutter.example/cache/temp/PDF_Document.pdf';
final pages = [0]; // The pages to import from the document
final insertPosition = 0; // Insert at the beginning of the document
final password = ''; // Password if the document is encrypted
final result = await controller.document.importDocument(
filePath: filePath,
pages: pages,
insertPosition: insertPosition,
password: password,
);
filePath The path of the PDF document to import. Must be a valid, accessible path on the device.
pages The pages to import from the document. If empty or not provided, the entire document will be imported.
insertPosition The position at which to insert the imported document in the current document.
If not specified, it defaults to -1 (append to the end).
password The password for the document if it is encrypted. Use an empty string if not encrypted.
Returns true if the document was successfully imported, false otherwise.
Throws an error if the native method call fails.
Implementation
Future<bool> importDocument(
{required String filePath,
List<int> pages = const [],
int insertPosition = -1,
String? password}) async {
return await _channel.invokeMethod('import_document', {
'file_path': filePath,
'pages': pages,
'insert_position': insertPosition,
'password': password
});
}