Skip to content

feat: configurable PDF export — page size, margins, orientation, page numbers - #7

Merged
sid8491 merged 1 commit into
masterfrom
feat-pdf-export-options
May 25, 2026
Merged

feat: configurable PDF export — page size, margins, orientation, page numbers#7
sid8491 merged 1 commit into
masterfrom
feat-pdf-export-options

Conversation

@sid8491

@sid8491 sid8491 commented May 25, 2026

Copy link
Copy Markdown
Owner

Summary

Surfaces the print knobs the existing webContents.printToPDF call already supports (the pipeline was hardcoded to A4 + default margins) and adds two genuinely new things: landscape orientation and an optional "X / Y" page-number footer. All settings live under a new PDF export section in the existing Settings modal and persist to localStorage so each user only configures once.

Controls

Setting Values
Page size A4, Letter, Legal, A3, A5, Tabloid
Margins Default (0.6in), Narrow (0.3in), None (0in)
Landscape orientation toggle
Print background toggle (off = force plain white)
Page numbers toggle (centred footer, forces ≥0.5in vertical margin so footer doesn''t overlap content)

Wiring

  • src/shared/types.tsExportPdfOptions gains landscape + displayPageNumbers; pageSize widens to the six Electron-supported sizes via a new PdfPageSize type.
  • src/main/ipc/pdf.ts — threads new options into printToPDF. When displayPageNumbers is on we disable preferCSSPageSize (the @page rule otherwise wins over Chromium''s runtime footer area) and inject minimal header (<div></div>) + footer (centred Inter pageNumber / totalPages) templates.
  • src/renderer/src/store/settings.ts — adds pdf: PdfPrefs with a single setPdf(partial) mutator; persisted alongside the existing theme/syncScroll/showLineNumbers fields.
  • src/renderer/src/lib/exportPdf.ts — reads useSettings.getState().pdf and threads it into the IPC call. Ctrl+E and the command-palette entry continue to "just work".
  • src/renderer/src/components/SettingsModal.tsx — new PdfExportSection rendered between About and AI provider, using the existing Field / Toggle / Select primitives so it matches the rest of the modal.

Tests

  • New src/renderer/src/store/settings.test.ts covers defaults, setPdf partial-merge semantics, and localStorage round-trip.
  • New vitest.setup.ts stubs window.matchMedia (jsdom doesn''t ship it) so any store that probes prefers-color-scheme at import time is safe to load in tests.
  • Wired in via vitest.config.ts > test.setupFiles.
Test Files  6 passed (6)
     Tests  28 passed | 1 todo (29)

Test plan

  • npm test, npm run lint, npm run typecheck, npm run format:check, npm run build all pass locally
  • Manual UI verification still needed: open Settings, change each control, export PDF, confirm output respects the choice
  • Especially: enable page numbers + narrow margins together and confirm the footer doesn''t collide with content (the auto-widen guard is for this)

Out of scope

  • Per-export overrides (a modal before save with these same controls). Easy follow-up if there''s demand.
  • Custom margin values (only presets right now).
  • User-customisable header/footer templates beyond the simple page-number footer.
  • Cover page / table of contents / outline embedding — bigger features in their own right.

… numbers

Adds a 'PDF export' section to Settings exposing the knobs the underlying
webContents.printToPDF call already supports, plus a couple of nice-to-haves:

- Page size: A4 / Letter / Legal / A3 / A5 / Tabloid (was hardcoded A4)
- Margins: Default / Narrow / None preset (was hardcoded Default)
- Landscape orientation toggle
- Print background toggle (lets users force plain-white if they want)
- Page numbers (X / Y centred footer) — automatically widens vertical
  margins to >=0.5in when on so the footer doesn't overlap content

Persisted to localStorage under marky:settings.pdf so each user only sets
their preferences once. exportToPdf() reads them at export time, so the
existing Ctrl+E shortcut and command-palette entry continue to 'just work'.

preferCSSPageSize is now disabled when page numbers are on — the @page
CSS rule otherwise overrides Chromium's runtime header/footer area.
@sid8491
sid8491 merged commit b7abbde into master May 25, 2026
3 checks passed
@sid8491
sid8491 deleted the feat-pdf-export-options branch May 25, 2026 18:20
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.

1 participant