Expo + React Native - PDF Creation & Download

做~自己de王妃 提交于 2021-02-10 14:04:28

问题


Is there a reliable way to create a file (specifically via Print.printToFileAsync API), and since it creates the new file in the user's cacheDirectory, copy it across to their documentDirectory - that works in both Android and iOS?

I've come across others trying to do the same thing here, but to no avail.

One solution I've seen is to use the MediaLibrary API to download the file to the device's CameraRoll - but this is hacky and doesn't work on iPhone since the file I'm trying to copy/download is a PDF, and not an image/movie.

Various solutions are listed here too - but they either don't work, or only work in one OS.

My end goal is to be able to generate a PDF on the device and save it to the user's storage, without needing to send information back to the server. My app is not ejected as it stands.

Any advice/direction would be appreciated!

EDIT 1:

Considering ejecting at some stage, but due to the nature of the project I'm working on I'd prefer to do that right at the end. Also came across this post which tries to Share the file URI, but this isn't supported on Android.


回答1:


I hope you dont have any problem with creating the pdf,to save the file have you tried

https://github.com/Lyrillind/react-native-file-manager

it supports both anroid and ios.

If you want you can build your own native module to save the file ,

http://facebook.github.io/react-native/docs/native-modules-ios.html#content



来源:https://stackoverflow.com/questions/55507959/expo-react-native-pdf-creation-download

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!