I want to test sending via email PDFs generated in my Expo Client app. I was doing some testing in a separate project and I was not able to make it work.
import React from 'react';
import { TouchableHighlight, Text, View } from 'react-native';
import * as Print from 'expo-print';
import * as FileSystem from 'expo-file-system';
import * as MailComposer from 'expo-mail-composer';
export default class App extends React.Component {
state = { uri: '' };
createPDF = () => {
let options = {
html: '<h1>PDF TEST</h1>'
};
Print.printToFileAsync(options)
.then(res => {
console.log(res);
this.setState({ uri: res.uri });
})
.catch(e => console.log(e));
};
sendEmail = () => {
FileSystem.readAsStringAsync(this.state.uri)
.then(doc => console.log(doc)) // send email..
.catch(e => console.log(e));
};
render() {
return (
<View style={{ justifyContent: 'center', alignItems: 'center', flex: 1 }}>
<TouchableHighlight style={{ padding: 10 }} onPress={this.createPDF}>
<Text>Create PDF</Text>
</TouchableHighlight>
<TouchableHighlight style={{ padding: 10 }} onPress={this.sendEmail}>
<Text>Send Email</Text>
</TouchableHighlight>
</View>
);
}
}
The error I’m getting is:
File 'file:///var/mobile/Containers/Data/Application/CF......862/Library/Caches/ExponentExperienceData/%2540turnosya%252FGeneradorPDF/Print/F.......5E1.pdf' could not be read.