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>
    );
  }
}
相关推荐
Hilaku2 小时前
2026 年了,jQuery 真的该死了吗?
前端·javascript·程序员
zach2 小时前
吃透 React setState 同步异步之谜:从批量更新、事件循环到版本演进的完整拆解
前端·react.js
不服老的小黑哥2 小时前
02-从 pnpm dev 到 Spring Boot 启动:后端服务到底怎么跑起来?
前端
htzyl2062 小时前
javaScript——this 的四种绑定:为什么箭头函数改不了它
前端·javascript
欧雷殿3 小时前
做自己的第一位客户:一人公司的数据治理公开实践
前端·ai编程·团队管理
掘金安东尼3 小时前
换上 Gemini 4 Neon 之后,我改了哪些上下文工程大模型
前端
用户298698530144 小时前
在 React 中实现 Excel 与 TXT 格式互转的前端方案
javascript·react.js·excel
涛涛ing4 小时前
我把项目里的 Zustand 全删了:代码量减半,Bug 少了,性能还起飞了
前端
map_3d_vis5 小时前
百度地图地图类型切换:普通地图、卫星图、混合图
前端·javascript·地图·百度地图
圆心角16 小时前
代码也有折旧率
前端·程序员