Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native - Create and Export/Download PDF File

Tags:

react-native

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?

like image 821
Maris Avatar asked Oct 01 '18 14:10

Maris


1 Answers

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

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.

like image 141
angelos_lex Avatar answered Nov 11 '22 06:11

angelos_lex