I need to a open pdf file from the local storage, here i use native_pdf_renderer: ^3.1.0 package for this purpose. As per the documentation, using the method PdfDocument.openFile('path/to/file/on/device')
will fetch file from local storage. But In my case it doesn't work, show's an error PlatformException (PlatformException(PDF_RENDER, Can't open file, null, null))
. The other methods PdfDocument.openAsset('assets/sample.pdf')
and PdfDocument.openData(uint8Data)
work's fine. How can this be made to work?
FilePickerResult result = await FilePicker.platform.pickFiles(
allowMultiple: false,
);
File doc = File(result.files.single.path);
PdfPageImage thePdfThumbNail = await getSinglePageImage(doc.path);
...
Future<PdfPageImage> getSinglePageImage(String path) async {
PdfDocument newDoc = await PdfDocument.openFile(path);
final page = await newDoc.getPage(1);
final pageImage = await page.render(
width: page.width,
height: page.height,
format: PdfPageFormat.JPEG,
);
return pageImage;
}