addBlankPageAt method
Adds a blank page at the given pageIndex
in the PDF.
Implementation
Future<File?> addBlankPageAt(int pageIndex, File pdfFile) async {
PdfDocument? pdfDoc;
try {
pdfDoc = PdfDocument(inputBytes: await readFileInChunks(pdfFile));
if (pageIndex < 0 || pageIndex > pdfDoc.pages.count) {
debugPrint('Invalid page index: $pageIndex');
return null;
}
final Size pageSize = Size(
pdfDoc.pages[0].getClientSize().width,
pdfDoc.pages[0].getClientSize().height,
);
pdfDoc.pages.insert(pageIndex, pageSize);
return await saveFile(
pdfDoc: pdfDoc,
addTimestap: false,
pdfFile: pdfFile,
);
} finally {
pdfDoc?.dispose();
}
}