【发布时间】:2021-07-05 03:47:20
【问题描述】:
我正在尝试使用 https://www.npmjs.com/package/react-native-pdf 将 base64 字符串转换为 pdf
我正在使用“react-native”:“0.64.0”,这是我的尝试,
import React, {useState, useEffect} from 'react';
import {Button,Image,View,Platform,Alert,StyleSheet,Dimensions,Text,} from 'react-native';
import Pdf from 'react-native-pdf';
export default function ImagePickerCamera() {
const source = {
uri:
'data:application/pdf;base64,/9j/4AAQSkZJRgA..............4R//Z',
cache: true, // tried with cache: false, not works
};
return (
<View style={styles.container}>
<Text>test</Text>
<Pdf
source={source}
onLoadComplete={(numberOfPages, filePath) => {
console.log(`number of pages: ${numberOfPages}`);
}}
onPageChanged={(page, numberOfPages) => {
console.log(`current page: ${page}`);
}}
onError={error => {
console.log(error);
}}
onPressLink={uri => {
console.log(`Link presse: ${uri}`);
}}
style={styles.pdf}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'flex-start',
alignItems: 'center',
marginTop: 25,
},
pdf: {
flex: 1,
width: Dimensions.get('window').width,
height: Dimensions.get('window').height,
},
});
我阅读了一些关于这个问题的文章,这是一个特定的问题来响应原生的 android,
https://github.com/wonday/react-native-pdf/issues/174
我没有找到解决方案,我尝试了一些建议,但对我不起作用。 任何人都可以知道,如何解决这个问题反应原生android,
【问题讨论】:
-
您确定您的网址有效吗?
-
我想是的,它是一个有效的 URL,我正在使用 base64-image.de 将图像转换为 base64 字符串,如果我使用 pdf URI 效果很好,我正在尝试使用 base64 字符串跨度>
标签: javascript android reactjs react-native pdf