Browser plugin required?
No—install the desktop client and npm package.
In Angular 15+ admin apps, wrap web-print-pdf printHtml in an Injectable service for silent output. Same npm API as the Vue and React guides.
npm install web-print-pdfComponent → Angular service → printHtml → local WebSocket client. See window.print alternative.
Create an injectable print service and call from components:
import { Injectable } from '@angular/core';
import webPrintPdf from 'web-print-pdf';
@Injectable({ providedIn: 'root' })
export class SilentPrintService {
async printHtml(html: string) {
return webPrintPdf.printHtml(
html,
{ paperFormat: 'A4', printBackground: true },
{ paperFormat: 'A4', printerName: '默认打印机' }
);
}
}
@Component({
template: `
<button (click)="onPrint()" [disabled]="loading">
{{ loading ? '打印中…' : '静默打印' }}
</button>
`
})
export class ReportPrintComponent {
loading = false;
constructor(private print: SilentPrintService) {}
async onPrint() {
this.loading = true;
try {
await this.print.printHtml(document.getElementById('report')!.innerHTML);
} finally {
this.loading = false;
}
}
}
angular.json config—run print logic in the browser only, not during SSR.@ViewChild on the table wrapper or a print-only template.getConnectStatus(); see error handling.Printing MatTable often pulls paginator, sort headers, or sidenav chrome onto paper.
mat-sidenav-containerNo—install the desktop client and npm package.
Call printHtml from browser click handlers only—not during server render.
Same npm API—Angular uses Services/DI.
Remove fixed/sticky containers or use a print-only HTML template without Material chrome.
Call printHtml from component click handlers after effects complete—not inside reducers.
The same web-print-pdf front-end runs on Windows, macOS, and Linux/domestic OS—install the matching client on each desktop.