将react-barcode转换为pdf格式以进行打印 [英] Convert react-barcode to pdf format to print
问题描述
我正在尝试打印生成的条形码,但它使用JSON.stringify和我得到但无法正常工作的所有其他来源打印为[object,object].有人可以建议最好的方法是什么.
I'm trying to print generated barcode but it prints as [object, object] tried using JSON.stringify and all other sources that i got but didn't work. Could someone suggest what is the best way to do this.
var printWindow = window.open('', '', 'height=400,width=800');
printWindow.document.write('<html><head><title>DIV
Contents</title>');
printWindow.document.write('</head><body >');
for(var i=0; i<selectedRows.length;i++){
printWindow.document.write(
<Barcode
value="Rakesh"//{this.state.value}
width="2"
height="100"
format="CODE128"
displayValue=""
fontOptions=""
font="monospace"
textAlign="center"
textPosition="bottom"
textMargin="2"
fontSize="20"
background="#ffffff"
lineColor="#000000"
margin="10"
marginTop=""
marginBottom=""
marginLeft=""
marginRight=""
/>
);
}
printWindow.document.write('</body></html>');
printWindow.document.close();
// printWindow.print();
推荐答案
根据您使用的React版本,您希望将该组件包装在React.renderToString
,React.renderComponent
或ReactDOMServer.renderToString
调用中.当然,这也意味着您需要确保React/ReactDOMServer在弹出窗口生成器的范围内.另请参见此答案.
Depending on the version of React you're using, you want to wrap that component in a React.renderToString
, React.renderComponent
, or a ReactDOMServer.renderToString
call. Of course, this also means that you need to make sure React/ReactDOMServer is within the scope of the popup window generator. See also this answer.
var ReactDOMServer = require('react-dom/server');
// ...
ReactDOMServer.renderToString(<Barcode
value="Rakesh"// {this.state.value}
width="2"
height="100"
format="CODE128"
displayValue=""
fontOptions=""
font="monospace"
textAlign="center"
textPosition="bottom"
textMargin="2"
fontSize="20"
background="#ffffff"
lineColor="#000000"
margin="10"
marginTop=""
marginBottom=""
marginLeft=""
marginRight=""
/>
)
这篇关于将react-barcode转换为pdf格式以进行打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!