Start Coding with Codelab | Jaeves AI

React native PDF Creator – ReadyMadeCode

Written by Admin | Sep 17, 2023 1:47:19 AM

React native PDF Creator

install package react-native-html-to-pdf.

import React, { Component } from 'react';

import {
  Text,
  TouchableHighlight,
  View,
} from 'react-native';

import RNHTMLtoPDF from 'react-native-html-to-pdf';

class Example extends Component {
  async createPDF() {
    let options = {
      html: '<h1>Example PDF</h1>',
      fileName: 'example',
      directory: 'Documents',
    };

    let file = await RNHTMLtoPDF.convert(options)
    console.log(file.filePath);
  }

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

export default Example;

click for more React codes