I'm trying to convert a web page to pdf file. for that I've been using webcontent_converter to doing this task.
IconButton(
onPressed: () async {
var dir = await getApplicationDocumentsDirectory();
var savedPath = (dir.path "sample.pdf");
var result = await WebcontentConverter.webUriToPdf(
uri:"https://xxxxxxx/xxxxxx/xxxxx",
savedPath: savedPath,
format: PaperFormat.a4,
margins:
PdfMargins.px(top: 35, bottom: 35, right: 35, left: 35),
);
await OpenFile.open(result);
WebcontentConverter.logger.info(result ?? '');
new Directory(result)
.create(recursive: true)
.then((Directory directory) async {
String path = directory.path;
File file;
file = await File(savedPath).create();
file.writeAsStringSync(path);
});
},
icon: Icon(Icons.save),
),
The pdf is not creating. I need to convert this WebView
to pdf
ad download it to download folder.
if there is any other package to do this. please suggest it as well
CodePudding user response:
result is not a path, it looks like it's some type of custom type. Log the return value of WebcontentConverter.webUriToPdf()
and make sure it's a path. You will need to have the device's persistent storage path as well, this package can help: https://pub.dev/packages/path_provider
And a path should look something like this: /docs/anotherfolder/somefoldername/file.pdf
CodePudding user response:
Based on the error message, I think you need to add slash /
before sample.pdf
.
await getApplicationDocumentsDirectory();
return is like this (no slash at the end)
'/home/user/Documents'
So you need to add the slash /
var savedPath = (dir.path "/sample.pdf");
or you can use join
var savedPath = join(dir.path, "sample.pdf");