react-native - 使用本机反应从wifi打印收据
问题描述
如何使用本机反应从wifi打印收据或文档?
我已经在 react native 中搜索了 print ,但大多数都显示了从蓝牙打印的选项,但我想从 wifi 打印,我该怎么做?
解决方案
检查它是否有帮助
import React, { Component } from 'react';
import {
AppRegistry,
Button,
StyleSheet,
NativeModules,
Platform,
Text,
View
} from 'react-native';
import RNHTMLtoPDF from 'react-native-html-to-pdf';
import RNPrint from 'react-native-print';
export default class RNPrintExample extends Component {
state = {
selectedPrinter: null
}
// @NOTE iOS Only
selectPrinter = async () => {
const selectedPrinter = await RNPrint.selectPrinter({ x: 100, y: 100 })
this.setState({ selectedPrinter })
}
// @NOTE iOS Only
silentPrint = async () => {
if (!this.state.selectedPrinter) {
alert('Must Select Printer First')
}
const jobName = await RNPrint.print({
printerURL: this.state.selectedPrinter.url,
html: '<h1>Silent Print</h1>'
})
}
async printHTML() {
await RNPrint.print({
html: '<h1>Heading 1</h1><h2>Heading 2</h2><h3>Heading 3</h3>'
})
}
async printPDF() {
const results = await RNHTMLtoPDF.convert({
html: '<h1>Custom converted PDF Document</h1>',
fileName: 'test',
base64: true,
})
await RNPrint.print({ filePath: results.filePath })
}
async printRemotePDF() {
await RNPrint.print({ filePath: 'https://graduateland.com/api/v2/users/jesper/cv' })
}
customOptions = () => {
return (
<View>
{this.state.selectedPrinter &&
<View>
<Text>{`Selected Printer Name: ${this.state.selectedPrinter.name}`}</Text>
<Text>{`Selected Printer URI: ${this.state.selectedPrinter.url}`}</Text>
</View>
}
<Button onPress={this.selectPrinter} title="Select Printer" />
<Button onPress={this.silentPrint} title="Silent Print" />
</View>
)
}
render() {
return (
<View style={styles.container}>
{Platform.OS === 'ios' && this.customOptions()}
<Button onPress={this.printHTML} title="Print HTML" />
<Button onPress={this.printPDF} title="Print PDF" />
<Button onPress={this.printRemotePDF} title="Print Remote PDF" />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
});
推荐阅读
- python - Kubernetes Python 客户端 API create_namespaced_binding() 方法显示 target.name: Required value 错误
- azure - 如何让 VSTS 使用 net Net Standard Azure Functions 找到我的 NetCore 单元测试?
- javascript - 图片高度显示为0,requestAnimationFrame(); javascript html5 游戏
- blender - Blender 骨骼约束问题
- r - 如何在列表中找到运行次数?
- sql - 向视图中的 SQL Server 函数提供参数
- raspberry-pi - Motion on Pi Zero W 低帧率
- angular - Angular Material Compose 日期选择器组件
- python - Python: N Puzzle (8-Puzzle) Solver Heuistics: 如何迭代?
- javascript - 在括号文本编辑器中链接单独的 .js 文件