import { useReactToPrint } from 'react-to-print';
const printsRef = useRef()
const handlePrint = useReactToPrint({
content: () => printsRef.current,
pageStyle: `
@page {
size: auto;
width: 80mm;
height: 1000mm;
margin-top: 0cm;
margin-right: 0mm;
margin-bottom: 0cm;
margin-left: 0cm;
}
`
})
In return function :
<table border={0} ref={printsRef}>
</table>
Suppose I'm using a button for the handlePrint function.
- This works perfectly. After clicking the print button, it pops up the Windows print dialog box.
- I want to ignore that printer selection dialog box and print directly to the default printer.
If you pass a custom function to the optional
printoptions onuseReactToPrintyou will get access to the iframe which you can then do whatever you want with. Can't say I know how to call the printer directly from Electron, but this should get you started: