saveFile method
Saves the modified pdfDoc either with or without a timestamp.
addTimestap decides whether to append a timestamp to the filename.
Implementation
Future<File?> saveFile({
bool addTimestap = false,
required File pdfFile,
required PdfDocument pdfDoc,
}) async {
final output = await getTemporaryDirectory();
final String originalName = pdfFile.path.split('/').last.split('.').first;
String savedPath = "";
if (addTimestap) {
final String timestamp = DateTime.now().millisecondsSinceEpoch.toString();
savedPath = '${output.path}/${originalName}_$timestamp.pdf';
} else {
savedPath = '${output.path}/$originalName.pdf';
}
final file = File(savedPath);
await file.writeAsBytes(await pdfDoc.save());
return file;
}