Element Plus silent printing

In Vue 3 + Element Plus admin apps, extract table or dialog HTML and call printHtml. Same architecture as the Vue guide.

Prerequisites

Integration pattern

Use a ref on the table wrapper or a dedicated print template; call printHtml on button click. See print options.

Element Plus table example

Wrap print logic in setup:

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 in template

import { useSilentPrint } from './useSilentPrint';

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

Tips

  • Clone el-table DOM or use a print-only template—avoid printing the whole layout.
  • Dialog print: capture content while el-dialog is open.
  • Preflight with getConnectStatus(); see error handling.
  • Works with Vite and Vue CLI—no special webpack config.

Common Element Plus table print pitfalls

Printing el-table often pulls in sidebars, pagers, and fixed-column shadows. Use a dedicated print DOM or template.

  • Sidebar/menu: clone .el-table only—not the #app root
  • Fixed columns: duplicate DOM—remove .el-table__fixed or use a plain HTML template
  • Pagination: default prints current page only—merge HTML or export server-side for full data
  • Dialog: ensure el-dialog content is rendered before capture

How this page fits with related guides

FAQ

Silent print Element Plus tables?

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

Modify Element Plus source?

No—DOM or template strings are enough.

What about hiprint?

See <a href="../hiprint-comparison/">hiprint comparison</a> for designer vs HTML workflows.

Fixed columns print twice?

Fixed columns duplicate table DOM—remove fixed containers or use a print-only template.

Vite dev cannot reach the client?

Framework-agnostic—start the client and preflight with getConnectStatus(). See error handling.

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