I am using pdf package to generate pdf. I was able to share the pdf but I don’t know, how to save the pdf in the local storage.
Future<void> sharePdf() async {
final pdf = pw.Document();
pdf.addPage(
pw.Page(
build: (pw.Context context) {
return pw.Container(
child: pw.Column(
children: [
pw.Text('Example', style: pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 20)),
]
),
);
}
),
);
final directory = await getExternalStorageDirectory();
final file = File("${directory?.path}/example.pdf");
final pdfBytes = await pdf.save();
await file.writeAsBytes(pdfBytes.toList());
await Share.shareFiles([(file.path)]);}
This is my code to share the pdf. I like to know how to save the pdf in the local storage.
3
Answers
With the help of other answers and document_file_save_plus package, I was able to save the pdf in local storage. This is the code
use this package doc_file_save
setp 1 :
add permission
android ->
ios ->
No permission needed. < as package documentation >
setp 2 : convert the file to Uint8List
setp 3: call this Function :
Then pass the Uint8List like this
I am sharing details process download file from url to save in local storage step by step if you already implemented Download just follow the savepdf File only.
call download function & pass url to the specific method
}
First download Pdf from http url
Save download file in stoarge by below function
Add read / write permissions in your android/app/src/main/AndroidManifest.xml before tag.
If you are still get the Permission Denied error, add the following line on AndroidManifest.xml file.
Don’t forget to add libray android pathprovider in pubspec.yaml