繁体   English   中英

FileSystemException:无法打开文件,路径 = '目录:'/storage/emulated/0/Android/data/

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

我正在尝试在我的设备上保存 pdf,但出现此错误

FileSystemException:无法打开文件,路径 = '目录:'/storage/emulated/0/Android/data/esofos.health/files'/test.pdf

这是生成文档的函数

_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();

};

使用Directory 路径属性而不是类的字符串表示。 像这样的东西:

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

检查提供的代码片段时,目录路径的类型转换不正确。 我们要求您更改以下代码以正确保存和打开 pdf 文件。

final path = directory!.path;

请参考以下文档链接,

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

注意:我为 Syncfusion 工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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