1

I am trying to send pdf of my entire view to mail or to message. I used react native html to pdf. but now pdf file saving in this path = "/data/user/0/com.medicare/cache/test2371693044570821246.pdf". but when Open that cache folder its empty. and when I share "file" to mail or message using share. then its just sharing [object object] <= like this. please help me.tel me the solution for this. or please tell me another library or another way by using which I am able to send my entire View in pdf format to mail or message.

here is my code

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>
    );
  }
}

2 Answers2

1

Not sure if you still need help with this but here is a potential solution.

Note:

You cannot generally view anything under /data unless an application which owns it has made it world readable (as explained in an answer here).

Solution:

Use the directory option to provide directory name where the file will be created (on iOS Documents is the only custom value that is accepted.)

let options = {
  html: "<h1>PDF TEST</h1>",
  fileName: "test",
  directory: "Documents",
};
K450
  • 691
  • 5
  • 17
0

I faced similar issue, try this
Go to file_manager in your phone and search for reverse domain of your app ex.(com.exampleApp)
you can able to see a folder with that domain name, then /files/Documents/yourpdf

abhish
  • 243
  • 4
  • 8