0

использую библиотеку '@react-pdf/renderer' чтобы сохранить данные в pdf

при использовании код от разработчика (https://snyk.io/advisor/npm-package/@react-pdf/renderer):

    import ReactPDF, { Document, Page, Text, View, StyleSheet } from '@react-pdf/renderer';

    // Create styles
    const styles = StyleSheet.create({
        page: {
        flexDirection: 'row',
        backgroundColor: '#E4E4E4'
        },
        section: {
        margin: 10,
        padding: 10,
        flexGrow: 1
        }
    });
    
    // Create Document Component
    const MyDocument = (): JSX.Element => (
        <Document>
            <Page size="A4" style={styles.page}>
                <View style={styles.section}>
                    <Text>Section #1</Text>
                </View>
                <View style={styles.section}>
                    <Text>Section #2</Text>
                </View>
            </Page>
        </Document>
    );

    ReactPDF.render(<MyDocument />, 'd://example.pdf');

получаю ошибку

Error: render is a Node specific API. You're either using this method in a browser, or your bundler is not loading react-pdf from the appropriate web build.

Подскажите пожалуйста с чем это может быть связано и как это можно исправить?

1 ответ 1

1

Как я могу видеть (и из ошибки) это библиотека не оринтирована на платформу ReactNative сугубо браузерное или Node.js использование. Собственно так как специфика и окруженение ReactNative другие мы не можем использововать в большинстве своем библиотеки для обычного реакта.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.