我想在react本地移动应用程序上打印一个pdf文件,我从api收到一个base64代码,通过使用它,我想向客户显示他/她的发票pdf。我试着使用Expo Print,但是我不能处理它,我一直收到
错误:对象作为React子级无效(已找到:具有键{_40,_65,_55,_72}的对象)。如果您打算呈现一个子集合,请改用数组。]
如果有任何帮助,我将不胜感激!
import React, { Component } from 'react';
import { View, Text, Button, StyleSheet,TouchableHighlight } from 'react-native';
import RNHTMLtoPDF from 'react-native-html-to-pdf';
import * as Print from 'expo-print';
const InvoiceScreen = async({ route, navigation }) => {
const { invoice} = route.params;
const my_uri = "data:application/pdf;base64"+invoice
console.log("DID INVIOCE COMEEE",invoice)
await Print.printAsync(
{uri:my_uri,
width: 595, height: 842 })
return (
<View></View>
);
};
export default InvoiceScreen;发布于 2021-05-31 04:26:54
使用以下代码替换您的代码:
const InvoiceScreen = async({ route, navigation }) => {
const { invoice } = route.params;
const my_uri = `data:application/pdf;base64,${invoice}`;
await Print.printAsync({uri:my_uri});
};
export default InvoiceScreen;发布于 2021-06-10 22:37:12
也许问题出在"invoice“参数的数据类型上,这必须是一个字符串,它必须是pdf文件的base64。Reference
如果你正在使用世博会管理的工作流程(世博会命令行/工具),要查看pdf,我建议你使用https://www.npmjs.com/package/rn-pdf-reader-js,我也在视图中留下一个简单的实现:
import React from "react";
import { View, StyleSheet, Dimensions } from "react-native";
import { globalStyles } from "../../constants/globalStyles";
import PDFReader from "rn-pdf-reader-js";
export default function XScreen({ navigation, route }) {
return (
<View style={globalStyles.backGround}>
<PDFReader
source={{
base64: route.params.source,
}}
style={styles.pdf}
/>
</View>
);
}
const styles = StyleSheet.create({
pdf: {
flex: 1,
width: Dimensions.get("window").width,
height: Dimensions.get("window").height,
},
});注意:
route.params.source =
data:application/pdf;base64,${response.data.data};
response.data.data = string base64 pdf
https://stackoverflow.com/questions/67727059
复制相似问题