Flutter 如何将生成的PDF保存到可访问存储?
我使用HTML-to-pdf插件从HTML代码生成了一个pdf 但它似乎将其保存在DocumentAppPath data/user/0/com.exmpl.myapp/app_flatter/中,这对于不太了解的用户来说并不容易访问Flutter 如何将生成的PDF保存到可访问存储?,flutter,Flutter,我使用HTML-to-pdf插件从HTML代码生成了一个pdf 但它似乎将其保存在DocumentAppPath data/user/0/com.exmpl.myapp/app_flatter/中,这对于不太了解的用户来说并不容易访问 Future<void> generateExampleDocument() async { var htmlContent = widget.htmlCont; // html Cv File's content Dire
Future<void> generateExampleDocument() async {
var htmlContent = widget.htmlCont; // html Cv File's content
Directory appDocDir = await getApplicationDocumentsDirectory(); // appDocDir
var targetPath = appDocDir.path;
var targetFileName = "example-pdf";
var generatedPdfFile = await FlutterHtmlToPdf.convertFromHtmlContent(
htmlContent, targetPath, targetFileName); // generates pdf document at the given path.
generatedPdfFilePath = generatedPdfFile.path; // variable outside function .
}
谢谢。我用过这个软件包。我有同样的任务,但我正在使用包从小部件生成pdf。然后我添加了保存按钮,它调用共享功能,可以选择将文件保存在手机上或发送给其他人
final sharePdf = await generatedPdfFile.readAsBytes();
await Share.file(
'PDF Document',
'project.pdf',
sharePdf.buffer.asUint8List(),
'*/*',
);
感谢您提供的快速信息,但这是否真的获得了权限并将其保存到用户可以访问的地方,还是什么?在调用pdf.save;~谢谢。如果您使用的是pdf软件包,请致电pdf.save。但正如我所看到的,html-to-pdf生成文件时不调用保存函数。它将打开ios和android的本机操作系统窗口,并询问用户如何处理该文件。保存它或通过信使、电子邮件等方式共享它。所以我想pdf包是一种方法?pdf包不能从html创建pdf。
final sharePdf = await generatedPdfFile.readAsBytes();
await Share.file(
'PDF Document',
'project.pdf',
sharePdf.buffer.asUint8List(),
'*/*',
);