Skip to content

Fix print2 pageSize: honour template CSS @page size when no explicit pageSize is passed#90

Draft
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-print2-pagesize-issue
Draft

Fix print2 pageSize: honour template CSS @page size when no explicit pageSize is passed#90
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-print2-pagesize-issue

Conversation

Copilot AI commented May 19, 2026

Copy link
Copy Markdown
Contributor

Electron's webContents.print() defaults preferCSSPageSize to false, silently ignoring the @page { size } rule the vue-plugin-hiprint template engine injects into every rendered HTML. This caused the printer to fall back to its hardware default paper regardless of the template's designed paper size.

Changes

  • src/print.js — added preferCSSPageSize to PRINT_WINDOW.webContents.print() (the print2 / "news" path)
  • src/render.js — same fix for RENDER_WINDOW.webContents.print() (render-print path)
  • README.md — documented the resulting default behaviour

Behaviour

Call preferCSSPageSize Paper source
print2(data, { printer }) — no pageSize true Template CSS @page { size } (receipt/label printers now work)
print2(data, { printer, pageSize: 'A4' }) false Explicit JS option wins
print2(data, { preferCSSPageSize: true/false, … }) user value User override
// Before: printer always used hardware default — template paper size ignored
WINDOW.webContents.print({ pageSize: data.pageSize });

// After: CSS @page { size } respected when no explicit pageSize is supplied
WINDOW.webContents.print({
  pageSize: data.pageSize,
  preferCSSPageSize: data.preferCSSPageSize ?? (data.pageSize == null),
});

…e is not explicitly specified

Agent-Logs-Url: https://github.com/CcSimple/electron-hiprint/sessions/fd83ea19-6308-42fa-af9d-e7e2ab6c4228

Co-authored-by: Xavier9896 <34981520+Xavier9896@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix pageSize parameter issue in print2 functionality Fix print2 pageSize: honour template CSS @page size when no explicit pageSize is passed May 19, 2026
Copilot AI requested a review from Xavier9896 May 19, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

print2 的 pageSize 参数无效,打印机会使用默认的纸张

2 participants