Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onPress={async () => {
const { type, uri, name, size } = await DocumentPicker.getDocumentAsync(
{},
);
if (type === 'success') {
onPick && onPick({ uri, name, size });
}
}}
>
_printDocumentPickerPDFAsync = async () => {
const { selectedPrinter } = this.state;
try {
const document = await DocumentPicker.getDocumentAsync({
type: 'application/pdf',
});
if (document.type !== 'success') {
throw new Error('User did not select a document');
}
await Print.printAsync({
uri: document.uri,
printerUrl: selectedPrinter ? selectedPrinter.url : undefined,
});
} catch (e) {
Alert.alert('Something went wrong: ', e.message);
}
};
_openPicker = async () => {
const result = await DocumentPicker.getDocumentAsync({
copyToCacheDirectory: this.state.copyToCache,
});
if (result.type === 'success') {
this.setState({ document: result });
} else {
setTimeout(() => {
Alert.alert('Document picked', JSON.stringify(result, null, 2));
}, 100);
}
}
_printDocumentPickerPDFAsync = async () => {
const { selectedPrinter } = this.state;
try {
const document = await DocumentPicker.getDocumentAsync({
type: 'application/pdf',
});
if (document.type !== 'success') {
throw new Error('User did not select a document');
}
await Print.printAsync({
uri: document.uri,
printerUrl: selectedPrinter ? selectedPrinter.url : undefined,
});
} catch (e) {
Alert.alert('Something went wrong: ', e.message);
}
}