createDocument static method
Creates a new PDF document without opening an existing file or using CPDFReaderWidget.
The returned document can be modified with APIs such as insertBlankPage, insertPageWithImagePath, and saveAs.
Since v2.6.8
example:
final document = await CPDFDocument.createDocument();
await document.insertBlankPage(pageIndex: 0);
await document.saveAs('/path/to/new_document.pdf');
Implementation
static Future<CPDFDocument> createDocument() async {
final id = CpdfUuidUtil.generateShortUniqueId();
final success = await ComPDFKit.createDocument(id);
if (!success) {
throw Exception('Failed to create document');
}
return CPDFDocument._(id, isValid: true);
}