Can Server Actions silent-print?
No. Silent print needs browser + local WebSocket client. Server Actions and Route Handlers cannot drive the user's printer.
In Next.js 14/15 (App or Pages Router), printing must run in the browser: call printHtml from a client component; the local client renders HTML→PDF→silent print. Same architecture as the React and Vue guides.
npm install web-print-pdf in your project"use client" to print components—never call printHtml from Server ComponentsCreate SilentPrintButton.tsx as a client component and call printHtml on button click:
'use client';
import { useState } from 'react';
import webPrintPdf from 'web-print-pdf';
export function SilentPrintButton({ html }: { html: string }) {
const [loading, setLoading] = useState(false);
return (
<button
disabled={loading}
onClick={async () => {
setLoading(true);
try {
await webPrintPdf.printHtml(html, { paperFormat: 'A4' }, { printerName: '默认打印机' });
} finally {
setLoading(false);
}
}}
>
{loading ? '打印中…' : '静默打印'}
</button>
);
}
Import that component from Server Component pages—do not import web-print-pdf directly in server layout.tsx / page.tsx.
In pages/**/*.tsx, import and call printHtml like any React app—only trigger from browser events, not during SSR.
"use client".webPrintPdf.utils.getConnectStatus() before printing.No. Silent print needs browser + local WebSocket client. Server Actions and Route Handlers cannot drive the user's printer.
You imported web-print-pdf in a Server Component. Move print logic to a use client component and call printHtml from click handlers only.
Same npm API—Next.js adds Server/Client component rules and use client.
Yes. Install the official client on each OS; printHtml code stays the same.
The same web-print-pdf front-end runs on Windows, macOS, and Linux/domestic OS—install the matching client on each desktop.