react native 'react-native-html-to-pdf' 警告

标签 react-native html-to-pdf

我正在使用“react-native-html-to-pdf”库。 我完全按照示例使用它,但出现错误。

警告 可能的未处理的 Promise 拒绝(id:0): 类型错误:无法读取未定义的属性“转换” 类型错误:无法读取未定义的属性“转换” 在createPDF$~~~~~~~~~~~~~~~~~~~~~~~~

https://github.com/christopherdro/react-native-html-to-pdf

import React, { Component } from 'react'
import { Text, View, Button, YellowBox, FlatList, Image, ScrollView, Dimensions, TouchableHighlight } from 'react-native'
import Swiper from 'react-native-swiper'
import {styles} from '../style/styles'
import RNHTMLtoPDF from 'react-native-html-to-pdf'

class NavtexPage extends Component {
  constructor(props) {//클래스가 생성될때 제일 먼저 실행되는 함수
    YellowBox.ignoreWarnings([
      'Warning: componentWillReceiveProps is deprecated',
      'Warning: componentWillUpdate is deprecated',
    ]);
    super(props);
    this.onPressNext = this.onPressNext.bind(this);
    this.onPressPrev = this.onPressPrev.bind(this);
    this.createPDF = this.createPDF.bind(this);

  }


  //깃허브 컴포넌트
  renderPagination = (index, total, context) => {
    return (
      <View style={styles.paginationStyle}>
        <Text style={{ color: 'grey' }}>
          <Text style={styles.paginationText}>{index + 1}</Text>/{total}
        </Text>
      </View>
    )
  }

  //이전
  onPressPrev = () => {
    const { indexPage } = this.state;
    if (indexPage > 0) {
      this.refs.swiper.scrollBy(-1);
    }
  }

  //다음
  onPressNext = () => {
    const { indexPage } = this.state;
    // Probably best set as a constant somewhere vs a hardcoded 5
    if (indexPage < 4) {
      this.refs.swiper.scrollBy(1);
    }
  }

  async createPDF() {//pdf libray
    let options = {
      html: '<h1>PDF TEST</h1>',
      fileName: 'test',
      directory: './data/',
    };
    console.log('pdf' + options)
    let file = await RNHTMLtoPDF.convert(options)
    // console.log(file.filePath);
    alert(file.filePath);
  }

  //시작
  render() {

    return (
      <View style={styles.container}>
        <View style={{ flex: 0.1, backgroundColor: 'green' }}>
          <Text>NAVTEX</Text>
        </View>

        {/* {깃허브 컴포넌트} */}
        <Swiper
          style={styles.wrapper}
          onIndexChanged={indexPage => this.setState({ indexPage })}
          renderPagination={this.renderPagination}
          showsButtons={false}
          loop={false}
          ref={'swiper'}
        >
          <View style={styles.slide}>
            <FlatList
              style={{ flex: 1, marginTop: 50, borderWidth: 1, borderColor: 'red' }}
              data={this.state.data}
              numColumns={1}
              renderItem={this._renderItem}
              keyExtractor={(item, index) => item.no.toString()}/>
          </View>
          <View style={styles.slide}>
            <Text style={styles.text}>2</Text>
          </View>
          <View style={styles.slide}>
            <Text style={styles.text}>3</Text>
          </View>
          <View style={styles.slide}>
            <Text style={styles.text}>4</Text>
          </View>
          <View style={styles.slide}>
            <Text style={styles.text}>5</Text>
            <TouchableHighlight  onPress={this.createPDF}>
              <Text>Create PDF</Text>
            </TouchableHighlight >
          </View>
        </Swiper>

        <View style={styles.buttoncontainer}>
          <Button
            style={{ with: 75 }}  
            onPress={this.onPressPrev}
            title="Previous">
          </Button>
          <Button
            onPress={this.onPressNext}
            title="Next">
          </Button>
        </View>
      </View>
    );
  }
}

最佳答案

这只是简单的链接错误

链接你的 npm :

react-native链接react-native-html-to-pdf

Android 全部设置完毕,IOS 需要安装 POD

cd ios, pod install

错误已解决

关于 react native 'react-native-html-to-pdf' 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57780629/

相关文章:

javascript - 使用 NavigationService 在 React 组件之外的 React Native 中导航、弹出、重置

reactjs - 如何在移动到下一个屏幕之前等待 React useEffect Hook 完成

javascript - 错误 : Realm context not found. 您是否在 <RealmProvider/> 中调用了 useRealm()?

pdf-generation - 文件保存在 wkhtmltopdf 中的位置

c# - HTML 到 PDF 使用 IronPDF 获取错误 "access to the path ' IronPdf.ChromeRenderingEngine.dll' 被拒绝。”在 C# 中

android - react-native run-android 第一次给出错误 500

ios - React Native Text 组件不会在 View 组件内居中

java - 使用iText在横向模式下将html转换为pdf

javascript - 图像未显示在从 HTML 创建的 PDF 上

javascript - 如何使用 jsPDF-AutoTable 插件自定义 PDF 中的标题单元格?