React Native HTML to PDF

Updated 5 May 2021

Save

In this blog, we are going to generate PDF file with the HTML string by using react-native HTML to pdf. So let’s get started.

We are using react-native-html-to-pdf to generate the PDF file from the HTML click here to check the npm page.

We just need the HTML string by the help of it we can generate the PDF.

Installation of npm module :

You just have to run the below mentioned command to install the npm module.

–> npm i react-native-html-to-pdf 

After that, we need to link the dependency by run the below-mentioned command.

–> react-native link

There is two way to link your libraries First is above it is automatic by run react-native link it will automatically link your libraries and the second one is manual.

IOS :

Android : 

  • Edit MainApplication.java to include

  • Add the following WRITE_EXTERNAL_STORAGE permission to AndroidManifest.xml
Note–> You have to add the WRITE_EXTERNAL_STORAGE permission in your AndroidManifes.xml file because the PDF file needs to save in internal storage.

By Android API version 6 (Marshmallow) we have to add the run time permissions in android so we need to be prompted for permission dynamically. Follow PermissionsAndroid link for more details on how to do that. The link is mentioned below.

So here our setup has been completed now let’s do some code. For instance, I have code to generate an html invoice to PDF.

Integration :

In conclusion, we will get the pdf file in file.

I hope it will help you.

After that, you can check out my other blogs by clicking here.

Reference link:- https://www.npmjs.com/package/react-native-touch-id ,

PermissionsAndroid:- http://reactnative.dev/docs/permissionsandroid

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home