Expo + React Native - PDF 创建 &下载 [英] Expo + React Native - PDF Creation & Download

查看:18
本文介绍了Expo + React Native - PDF 创建 &下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可靠的方法来创建文件(特别是通过 Print.printToFileAsync API),因为它在用户的 cacheDirectory,将其复制到他们的 documentDirectory - 在 Android 和 iOS 中都可以使用?

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.

我见过的一个解决方案是 使用 MediaLibrary API 将文件下载到设备的 CameraRoll - 但这是 hacky 并且不适用于 iPhone,因为我要复制/下载的文件是 PDF,而不是图像/电影.

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.

我的最终目标是能够在设备上生成 PDF 并将其保存到用户的存储中,而无需将信息发送回服务器.我的应用程序没有按原样弹出.

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!

编辑 1:

考虑在某个阶段退出,但由于我正在从事的项目的性质,我更愿意在最后这样做.还遇到了 这篇试图共享文件 URI,但 Android 不支持.

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.

推荐答案

希望您在创建pdf时没有任何问题,保存文件您尝试过吗

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

它同时支持安卓和ios.

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

这篇关于Expo + React Native - PDF 创建 &下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆