React Native - 创建和导出/下载 PDF 文件 [英] React Native - Create and Export/Download PDF File

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

问题描述

我正在 React Native 中创建一个项目,该项目创建一个包含一些数据的表,我需要使用该表创建一个 pdf 并能够下载/导出该 pdf.目前我正在使用 https://github.com/christopherdro/react-native-html-to-pdf,但它下载到缓存目录,即使我更改为文档.我在搜索,有人说你需要使用文件管理器来下载 pdf.有人可以帮我吗?

I'm making a project in React Native that creates a table with some data, and I need to create a pdf with that table and be able to download/export that pdf. Currently i'm using https://github.com/christopherdro/react-native-html-to-pdf, but its downloading to cache directory, even if i change to docs. I was searching and some people say that u need to use file manager to download a pdf. Can someone help me?

推荐答案

从 docs 开始,如果你想把它保存在 ios/android 的 Documents 目录,你必须指定Documents"目录.

From docs, you have to specify "Documents" directory if you want it to be saved on Documents dir of ios/android.

  async createPDF() {
        let options = {
            html: '<table><tr><th>Firstname</th><th>Lastname</th></tr></table>',
            fileName: 'tableTest',
            directory: 'Documents',
        };
        let file = await RNHTMLtoPDF.convert(options)
        alert(file.filePath);
  }

由于您是在 React Native 代码中创建此表,因此您无需从任何地方下载任何内容.缓存目录是你手机的缓存目录,所以我不明白你想从哪里下载pdf.

Since you are creating this table in your react native code, you don't need to download anything from anywhere. Cache directory is your phone's cache directory, so I can't understand from where you want to download the pdf.

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

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