本文主要是介绍react- native创建pdf,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
npm i react-native-html-to-pdf
- 向
AndroidManifest.xml
添加以下WRITE_EXTERNAL_STORAGE
权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
使用:
import React, { Component } from 'react';
import {Text,TouchableHighlight,View,
} from 'react-native';
import RNHTMLtoPDF from 'react-native-html-to-pdf';export default class Example extends Component {async createPDF() {const options = {html: '<h1>PDF 测试</h1>',fileName: 'test',directory: 'Documents',};const file = await RNHTMLtoPDF.convert(options);// console.log(file.filePath);alert(file.filePath);}render() {return (<View><TouchableHighlight onPress={this.createPDF}><Text>创建PDF</Text></TouchableHighlight></View>);}
}
这篇关于react- native创建pdf的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!