简体   繁体   中英

FileSystemException: Cannot open file, path = 'Directory: '/storage/emulated/0/Android/data/

I'm trying to save a pdf on my device , but i got this error

FileSystemException: Cannot open file, path = 'Directory: '/storage/emulated/0/Android/data/esofos.health/files'/test.pdf

this is the function that generate the document

_generatepdf() async {

//Get external storage directory
final directory = await getExternalStorageDirectory();
//Get directory path
final path = directory;
// Create a new PDF document.
final PdfDocument document = PdfDocument();
// Add a PDF page and draw text.
document.pages.add().graphics.drawString(
    'Hello World!', PdfStandardFont(PdfFontFamily.helvetica, 12),
    brush: PdfSolidBrush(PdfColor(0, 0, 0)),
    bounds: const Rect.fromLTWH(0, 0, 150, 20));

// Save the document.
print(path);
File('$path/test.pdf').writeAsBytes(document.save());
// Dispose the document.
document.dispose();

};

Use Directory path property not string representation of class. Something like this:

File('${directory.path}/test.pdf').writeAsBytes(document.save());

When checking the provided code snippet, the directory path was not type casted properly. We request you to change the below code to save and open the pdf file properly.

final path = directory!.path;

Please refer to the below documentation link,

UG: https://help.syncfusion.com/flutter/pdf/getting-started#save-and-open-a-pdf-document-in-mobile

Note: I work for Syncfusion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM