JSFiddle - React, Tailwind, and code Playground

by ph822720355

HTML

<!DOCTYPE html>
<html>
<head>
    <title>Print Page with Custom Page Numbers</title>
    <script src="https://printjs-4de6.kxcdn.com/print.min.js"></script>
</head>
<body>
    <h1>Print Page with Custom Page Numbers</h1>
    <button onclick="printPage()">Print</button>

    <script>
        function printPage() {
            // 使用 print.js 的 API 来定义打印页面
            printJS({
                printable: 'body',
                header: '<h1>Custom Header</h1>',
                footer: '<h3>Page {pageNumber} of {totalPages}</h3>',
                style: 'h1 { color: red; }',
            });
        }
    </script>
</body>
</html>