flutter_pdfview icon indicating copy to clipboard operation
flutter_pdfview copied to clipboard

how to load pdf from assets when pdf loaded from json file

Open janbildsoehansen opened this issue 3 years ago • 7 comments

Hey im struggling with how to load pdf from assets when loaded from json file

janbildsoehansen avatar Apr 05 '21 01:04 janbildsoehansen

You need to load asset file and pass to a file like this example

Future<String> fromAssetToFile(String asset, String filename) async {
    try {
      var data = await rootBundle.load(asset);
      var bytes = data.buffer.asUint8List();
      File file = File("${widget.directorio.path}/$filename");
      File assetFile;
      if (file.existsSync()) {
        return file.path;
      } else {
        assetFile = await file.writeAsBytes(bytes);
        return assetFile.path;
      }
    } catch (e) {
      throw Exception('Error parsing asset file! $e');
    }
  }

rodi189 avatar Apr 16 '21 20:04 rodi189

Thanks Will try it out 🤘🏼

janbildsoehansen avatar Apr 16 '21 20:04 janbildsoehansen

whats the directorio string..???

janbildsoehansen avatar Apr 17 '21 16:04 janbildsoehansen

whats the directorio string..???

Is from getapplicationdocumentsdirectory() in package path_provider

https://pub.dev/packages/path_provider

rodi189 avatar Apr 25 '21 03:04 rodi189

okay i cant get it to work... i dont know what im doing hehe

janbildsoehansen avatar Apr 26 '21 08:04 janbildsoehansen

you cant find any build with this its all the same shit load on push on a button whats with that..??

if you make a example you will be the first on the whole internet to do so im pretty sure

janbildsoehansen avatar Apr 26 '21 08:04 janbildsoehansen