sorry for my bad english, i'm a beginner, i want to generate pdf with html and download it into downloads, so i try like the expo-print documentation but the problem it give me an empty pdf with 0kb size in my brother phone (redmi note 10S), and everything works perfect in my phone (huawei y8 prime).
import React, { useState } from "react";
import {
View,
Text,
Dimensions,
TouchableOpacity,
Button,
ScrollView,
Platform,
TextInput,
} from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
import { themeColors } from "../../theme";
import { useNavigation } from "@react-navigation/native";
import * as Print from "expo-print";
import { shareAsync } from "expo-sharing";
const html = `
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
</head>
<body style="text-align: center;">
<h1 style="font-size: 50px; font-family: Helvetica Neue; font-weight: normal;">
Hello World!
</h1>
<img
src="https://d30j33t1r58ioz.cloudfront.net/static/guides/sdk.png"
style="width: 90vw;" />
</body>
</html>
`;
const CreatelunchSheet = () => {
const [selectedPrinter, setSelectedPrinter] = useState();
const print = async () => {
await Print.printToFileAsync({
html,
printerUrl: selectedPrinter?.url, // iOS only
});
}
const selectPrinter = async () => {
const printer = await Print.selectPrinterAsync(); // iOS only
setSelectedPrinter(printer);
};
return (
<SafeAreaView>
<TouchableOpacity
style={{
backgroundColor: "white",
marginLeft: screenWidth * 0.05,
width: screenWidth * 0.2,
borderColor: themeColors.bgColor(1),
}}
onPress={print}
className=" p-1 flex justify-center items-center rounded-md border "
>
<Text
style={{
fontFamily: "arabswell_1",
fontSize: 22,
}}
className=""
>
download
</Text>
</TouchableOpacity>
{Platform.OS === "ios" && (
<>
<TouchableOpacity
style={{
backgroundColor: "white",
marginLeft: screenWidth * 0.05,
width: screenWidth * 0.2,
}}
onPress={selectPrinter}
className=" p-1 flex justify-center items-center rounded-md border "
>
<Text
style={{
fontFamily: "arabswell_1",
fontSize: 22,
}}
className=""
>
select printer
</Text>
</TouchableOpacity>
</>
)}
)
</SafeAreaView>
}
export default CreatelunchSheet;