如何在本机反应中打印屏幕内容?

Jas*_*son 6 printing react-native

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

Jas*_*son 4

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

import RNPrint from 'react-native-print';

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

RNPrint.print({html: htmlString});
Run Code Online (Sandbox Code Playgroud)

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

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

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