How can I show a pdf in base64 in flutter?
2,419
I didn't test it but you have flutter package displaying pdf : flutter full pdf viewer You can find here an example of using this package with a pdf asset.
Author by
jhap
Updated on December 12, 2022Comments
-
jhap over 1 year
I have the content of a pdf in base64 and I need to show it in a container in a flutter application.
I'm trying to do it with the image, pdf and convert packages from dart,but I get an error with the image class and I don't know how to show the image.
List<int> pdfDataBytes = base64.decode(fileContent); Image img = decodeImage(pdfDataBytes); PdfImage image = PdfImage( pdf, image: img.data.buffer.asUint8List(), width: img.width, height: img.height);
This is the message of the error in the image class: Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports
-
jhap almost 5 yearsThanks, but the article shows it with a pdf file in a path, I only have the content in base64
-
hawkbee almost 5 yearsCan't you store your content in a file ?
-
hawkbee almost 5 yearsFuture<String> _createFileFromString() async { final encodedStr = "put base64 encoded string here"; Uint8List bytes = base64.decode(encodedStr); String dir = (await getApplicationDocumentsDirectory()).path; File file = File( "$dir/" + DateTime.now().millisecondsSinceEpoch.toString() + ".pdf"); await file.writeAsBytes(bytes); return file.path; }
-
jhap almost 5 yearswhere do you get the method? "The method 'getApplicationDocumentsDirectory' isn't defined for the class"
-
hawkbee almost 5 yearsgetApplicationDocumentsDirectory is from the package path_provider pub.dev/packages/path_provider