Print Data To PDF in React-Native. I have seen many tutorials but haven't got the exact answer to this question.
Invoice.js
import React from 'react';
import { View, SafeAreaView ,StyleSheet, ScrollView, Button, Platform, Text } from "react-native";
import { Card } from "react-native-elements";
import { DataTable } from "react-native-paper";
import Pdf from "../components/Pdf";
const Invoice = () => {
return (
<SafeAreaView>
<ScrollView>
<Card>
<Text h3>Invoice #7654</Text>
<View>
<Text>
<Text style={{ fontWeight: "bold" }}>From:</Text>
{"\n"}Tata 56 view Pune
{"\n"}Email: sumit@.com
{"\n"}Phone: 5252146954
</Text>
</View>
<Pdf />
</Card>
</ScrollView>
</SafeAreaView>
);
}
export default Invoice
Pdf.js
import * as React from 'react';
import { View, StyleSheet, Button, Platform, Text } from 'react-native';
import * as Print from 'expo-print';
import { shareAsync } from 'expo-sharing';
import RNPrint from 'react-native-print';
import Invoice from './Invoice';
export default function Pdf() {
const printToFile = async () => {
const { uri } = await Print.printToFileAsync({
<Invoice />
});
console.log('File has been saved to:', uri);
await shareAsync(uri, { UTI: '.pdf', mimeType: 'application/pdf' });
}
return (
<View style={styles.container}>
<View />
<Button title="Print to PDF file" onPress={printToFile} />
</View>
);
}
const styles = StyleSheet.create({
container:{
marginTop: 20
}
});
I want to print the Invoice.js which I am importing in pdf. Any suggestions on how to print PDF in React-Native?