Aidra Connect 10.0.2+16
Aidra Connect Mobile Application
Loading...
Searching...
No Matches
pdf_util.dart
Go to the documentation of this file.
1import 'dart:convert';
2import 'dart:io';
3
4import 'package:open_filex/open_filex.dart';
5import 'package:path_provider/path_provider.dart';
6
7class PdfUtils {
12 static Future<String> openBase64Pdf(
13 String base64String, String fileName) async {
14 try {
15 // Decode the base64 string
16 final List<int> bytes = base64.decode(base64String);
17
18 // Get temporary directory for file storage
19 final Directory tempDir = await getTemporaryDirectory();
20
21 // Create file in temporary directory
22 final File file = File('${tempDir.path}/$fileName');
23
24 // Write decoded bytes to file
25 await file.writeAsBytes(bytes);
26
27 // Open the PDF file
28 final result = await OpenFilex.open(file.path);
29
30 if (result.type != ResultType.done) {
31 throw Exception('Could not open the file: ${result.message}');
32 }
33
34 return file.path;
35 } catch (e) {
36 throw Exception('Failed to process PDF: $e');
37 }
38 }
39}
static Future< String > openBase64Pdf(String base64String, String fileName) async
Converts base64 string to PDF file and opens it.
Definition pdf_util.dart:12