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>
    );
  }
}
相关推荐
tiandyoin1 小时前
Notepad++ 修改 About
前端·notepad++·html5
纪伊路上盛名在2 小时前
商务办公tips2:如何获取网页内嵌pdf文件
学习·搜索引擎·pdf·学习方法·everything
职场人参2 小时前
怎么将几个pdf合成为一个?把几个PDF合并成为一个的8种方法
前端
飘逸高铁侠2 小时前
使用Python实现多个PDF文件的合并
开发语言·python·pdf
学前端搞口饭吃3 小时前
vue2-ssr从vue-cli搭建项目改造服务端渲染+打包上线部署
前端·javascript·vue.js
CRMEB系统商城3 小时前
前端项目node版本问题导致依赖安装异常的处理办法
前端
anyup_前端梦工厂3 小时前
Vue 中常用的基础指令
前端·javascript·vue.js
coderYYY3 小时前
CSS实现原生table可拖拽调整列宽
前端·css·html·css3
箬敏伊儿4 小时前
springboot项目中 前端浏览器访问时遇到跨域请求问题CORS怎么解决?has been blocked by CORS policy
java·前端·spring boot·后端·spring
2301_789169544 小时前
react crash course 2024 (1)理论概念
前端·react.js·前端框架