Does React silent print need a browser plugin?
No browser plugin—install the Web Print Expert client and npm install web-print-pdf.
Use web-print-pdf in React 18 for silent printing—the local client renders HTML to PDF without a browser dialog. Same architecture as the Vue guide; below is a React Hook pattern.
npm install web-print-pdfReact calls printHtml → npm submits via local WebSocket → client prints silently. See window.print alternative for the full picture.
Wrap useSilentPrint and pass print-area HTML on button click:
import { useCallback, useState } from 'react';
import webPrintPdf from 'web-print-pdf';
export function useSilentPrint() {
const [loading, setLoading] = useState(false);
const printHtml = useCallback(async (html) => {
setLoading(true);
try {
return await webPrintPdf.printHtml(
html,
{ paperFormat: 'A4', printBackground: true },
{ paperFormat: 'A4', printerName: '默认打印机' }
);
} finally {
setLoading(false);
}
}, []);
return { loading, printHtml };
}
import { useSilentPrint } from './useSilentPrint';
export function OrderPrintButton({ html }) {
const { loading, printHtml } = useSilentPrint();
return (
<button disabled={loading} onClick={() => printHtml(html)}>
{loading ? '打印中…' : '静默打印'}
</button>
);
}
@media print or a dedicated stylesheet.window.print dialogs—common in intranet policies.webPrintPdf.utils.getConnectStatus().No browser plugin—install the Web Print Expert client and npm install web-print-pdf.
Yes—in client components ("use client"), import and call printHtml; printing runs in the browser only.
Same npm API; React uses Hooks/events. See the Vue page for WebSocket protocol details.
The same web-print-pdf front-end runs on Windows, macOS, and Linux/domestic OS—install the matching client on each desktop.