gpt4 book ai didi

react-native - 如何在 native react 中打印屏幕内容?

转载 作者:行者123 更新时间:2023-12-02 17:48:00 26 4
gpt4 key购买 nike

有没有办法在 React Native 中将屏幕内容(包含渲染的图像)打印到打印机?我研究了 react-native-print 但它只接受 HTML 文本,而 react-native-xprinter 仅支持 Android。谢谢。

最佳答案

设法让它发挥作用。请参阅下面的代码。

import RNPrint from 'react-native-print';

var htmlString = `<div style="(your CSS style here)"> (HTML contents here) </div>`;

RNPrint.print({html: htmlString});

如果您想在 HTML 中嵌入图像,请参见下文:

var htmlString = `<div style="(your CSS style here)"> 
<img src="data:image/png;base64, ${imgData}" style="width: $imgWidth; height: $imgHeight"/>
</div>`;

您可以将“image/png”替换为其他图像类型。希望这会有所帮助。

关于react-native - 如何在 native react 中打印屏幕内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47903985/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com