react native html to pdf创建的pdf未显示在提供的路径中 注意:解决方案:

问题描述

我正在尝试将我的整个视图的 pdf 发送到邮件或消息。我使用 react native html to pdf。但现在保存在此路径中的pdf文件=“/data/user/0/com.medicare/cache/test2371693044570821246.pdf”。但是当打开那个缓存文件夹时它是空的。当我使用共享将“文件”共享到邮件或消息时。然后它只是像这样共享 [object object]

这是我的代码

export default class Example extends Component {
 
  createPDF = async () => {
    let options = {
      html: "<h1>PDF TEST</h1>",fileName: "test",};
    let file = await RNHTMLtoPDF.convert(options);
    alert(file);
    console.log(file);

    Share.share({
      title: "This is my report ",message: `${file}`,subject: "Report",});
    console.log("hoo");
  };

  render() {
    return (
      <View>
        <TouchableHighlight onPress={this.createPDF}>
          <Text>Create PDF</Text>
        </TouchableHighlight>
      </View>
    );
  }
}

解决方法

不确定您是否还需要这方面的帮助,但这里有一个潜在的解决方案。

注意:

您通常无法查看 /data 下的任何内容,除非拥有它的应用程序已使其世界可读(如答案 here 中所述)。

解决方案:

使用 directory 选项提供将在其中创建文件的目录名称 (on iOS Documents is the only custom value that is accepted.)

let options = {
  html: "<h1>PDF TEST</h1>",fileName: "test",directory: "Documents",};