Expo print isn´t printing an custom html

Environment: “react-native-web”: “~0.11.7”, “expo-print”: “~9.0.1”, “expo”: “~38.0.8”

Expected behaviour: print an pdf passing an “html”

    const htmlContent = `
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Pdf Content</title>
        <style>
            body {
                font-size: 16px;
                color: rgb(255, 196, 0);
            }            h1 {
                text-align: center;
            }
        </style>
    </head>
    <body>
        <h1>Hello, Unica Exames!</h1>
    </body>
    </html>
`;

const createPDF = async (html) => {
    console.log(html);
    try {
        const { uri } = await Print.printToFileAsync({ html });
        console.log(uri);
        return uri;
    } catch (err) {
        console.error(err);
    }
};

export const PrescriptionPage  = ({ navigation }) => {
    return(
        <View style={{flex: 1}}>
            <SafeAreaView style={{ flex: 1, width: null, height: null }}>
                <ImageBackground source={backgroundImage} style={styles.backgroundContainer}>
                    <TouchableOpacity style={styles.sideOptionsButton} onPress={() => createPDF(htmlContent)}>
                        <Ionicons name='ios-menu' size={28} color='#ffffff' />
                    </TouchableOpacity>
                    <Text style={styles.logoTextStyle}>PrescriptionPage</Text>
                </ImageBackground>
            </SafeAreaView>
        </View>
    );
};

What is happening: the function is printing the content of “PrescriptionPage”

In the log the error is showing: TypeError: _await$Print$printToF is undefined

The problem is async await you should create one more constant like loader which will be true untill the data is not fetched
And use that value which will store the data from await after the loader is false

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.