Ant Design / Pro silent printing

In React + Ant Design or Ant Design Pro admin apps, extract Table / ProTable HTML and call printHtml. See the React guide for basics.

Prerequisites

Integration pattern

Wrap the table with a ref or build a print-only HTML string; call printHtml from toolbar actions. See print options.

Ant Design Table example

Same Hook pattern as the React guide:

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 };
}

Bind on ProTable / Table toolbar

import { useSilentPrint } from './useSilentPrint';

export function OrderPrintButton({ html }) {
  const { loading, printHtml } = useSilentPrint();
  return (
    <button disabled={loading} onClick={() => printHtml(html)}>
      {loading ? '打印中…' : '静默打印'}
    </button>
  );
}

Tips

  • Clone .ant-table-content or use a print template—avoid printing ProLayout chrome.
  • Modal print: capture content while open.
  • Preflight with getConnectStatus(); see error handling.
  • Works with Umi, Vite, and CRA; TypeScript types built in.

Ant Design Table / ProTable print pitfalls

ProLayout chrome, ProTable filters, fixed columns, and horizontal scroll are common extra content on paper.

  • ProLayout: capture .ant-table-content or a template—not the full layout
  • ProTable filters: bind print to table DOM, not the search Form
  • Fixed columns: same duplication issue—print templates are safer
  • Modal/Drawer: capture while open

How this page fits with related guides

FAQ

Silent Ant Design tables?

Yes—extract HTML and call printHtml via the local client.

Will ProTable filters print?

By default yes—select table DOM or a dedicated template.

vs react-to-print?

react-to-print often uses the browser dialog; web-print-pdf adds silent named-printer output.

Will ProTable filters print?

By default yes—select table DOM or a dedicated HTML template.

Umi / CRA integration?

Build-tool agnostic: npm install web-print-pdf and import—TypeScript types built in.

Client deployment by platform

The same web-print-pdf front-end runs on Windows, macOS, and Linux/domestic OS—install the matching client on each desktop.

Download client — free trial View npm package Documentation