[FEATURE REQUEST] Card-size PDF export for cards (cardwallet)

Open
#863 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
ios, kotlin, typescript
Domain
full-stack, mobile

Research direction

Start with app/utils/pdfPaper.ts and its proposed tests, then trace PDF sizing and drawing through app/services/pdf/PDFCanvas.ts, app/services/pdf/PDFExportCanvas.ios.ts, and the Android PDFUtils.kt path listed in the issue. Check how PDF_OPTIONS controls cardwallet settings and preview behavior. Done means cardwallet exports one correctly sized page per card side with fitted images, and the optional rounded corners work in preview and on Android and iOS.

Written by the indexing model from the issue text.

Description

enhancement wallet

Is your feature request related to a problem?
Exporting an ID card (2 sides) to PDF gives either huge pages (full = image pixels as points, not a physical size) or A4 sheets. There is no way to get one card side per card-sized page, nor to clip the scan to the rounded corners of the card. Split out of #439 (maintainer idea: an export preset with "card size" pages). Refs #439.

Describe the solution you'd like
In the cardwallet app only: a card paper size (ISO/IEC 7810 ID-1, 85.6 x 54 mm = 242.65 x 153.07 pt), one card side per page, plus an optional "rounded corners" switch.

🎯 Plan

📋 Context

Extension of the PDF export options. Cardwallet only (CARD_APP); the document scanner app is untouched.

Assumptions:

  • "1 page with card size pages" = one card side per card-size page (2 pages for a 2-sided card). Both sides on one sheet is already covered by A4 + 2 items per page.
  • Preset = one new paper_size value, not a named option bundle.
  • Corner radius is a ratio of the short side (3.18 / 53.98 = 0.059): exact only when the scan is cropped to the card.
  • PKPass pages are not card-fitted (they keep their own layout); only image pages are.
🛠️ Recommended approach
  • New paper_size: 'card', added to PDF_OPTIONS.paper_size only when CARD_APP. Settings, sync settings and the layout sheet menu are built from PDF_OPTIONS, so no extra UI is needed.
  • It behaves like full (1 item per page, margins ignored) with a fixed physical size. Orientation follows the first image (landscape or portrait), so picking it from Settings alone gives a correct page. The image is fitted and centered, embedded at full resolution.
  • round_corners boolean (default off), shown only in cardwallet and usable with any paper size (also A4 2-up). Applied at image draw time, before rotation: Android masks the bitmap in loadImage and writes the corners white (keeps JPEG); iOS uses canvas.clipPath with a rounded rect. White corners are invisible on a white page.
  • Page sizes are hardcoded in 4 places today (Kotlin, iOS switch, PDFCanvas ratio switch, PDFPreview PAPERS): share one TS table app/utils/pdfPaper.ts for the 3 TS callers; Kotlin keeps its own constants with a "keep in sync" comment (as for the OCR constants).
  • Per-card remembered export settings (separate idea) compose: card and round_corners are plain option keys. On Android exportPDFAsync merges the persisted default_export_options with the passed options, so per-card options must be passed explicitly.
📂 Impacted files
File Action Description
app/utils/pdfPaper.ts (+ .test.ts) Create PAPERS in pt (card included), isSinglePage(paper_size), getCardPageSize(w, h, rotation)
app/utils/constants.ts Edit CARD_CORNER_RADIUS_RATIO; round_corners: false in DEFAULT_PDF_OPTIONS and PDF_LAYOUT_KEYS
app/utils/localized_constant.ts Edit paper_size.card, only when CARD_APP
app/services/pdf/PDFCanvas.ts Edit card through the single-page branch of updatePages / drawPages; fit and center; round_corners clip
app/services/pdf/PDFExportCanvas.ios.ts Edit card case in the size switch; no orientation swap for card
plugin-nativeprocessor/platforms/android/.../PDFUtils.kt Edit card branch (page size, fit and center, OCR offset); round_corners mask in loadImage
app/components/pdf/PDFPreview.svelte Edit Use pdfPaper.ts; card sheet ratio from the first page; margin 0; rounded <image> preview
app/components/pdf/PDFLayoutSheet.svelte Edit Dim orientation / items / margin for card like full; "rounded corners" switch row (cardwallet only)
app/i18n/en.json Edit card_size, pdf_layout_card_hint, round_corners, round_corners_desc
📝 Steps
  1. pdfPaper.ts test-first (red, then green). Wire PDFPreview and PDFCanvas to it, no behaviour change.
  2. Add card to constants and labels (cardwallet only). Preview and layout sheet show it, with the hint.
  3. iOS export for card; Android card branch in Kotlin.
  4. Add round_corners: option, sheet row, iOS clip, Android mask, preview radius.
  5. yarn svelte-check, eslint on changed files, vitest, manual check on both platforms.

Suggested split: commit/PR 1 = card paper size (steps 1-3), commit/PR 2 = rounded corners (step 4).

🧪 Test strategy
Type Scenario File
Unit getCardPageSize: landscape image -> 242.65 x 153.07, portrait -> swapped, rotation 90 -> swapped; isSinglePage('card') / ('full') true, ('a4') false; radius ratio ~0.059 app/utils/pdfPaper.test.ts (red first, mutation-checked)
Manual, native Export a 2-sided card: 2 pages of 85.6 x 54 mm, image fitted, OCR text layer aligned, portrait scan gives a portrait page. Android + iOS device / simulator
Manual, native round_corners on card and on A4 2-up: white corners, no seam; page rotated 90 / 180 correct; preview matches export device / simulator
Manual Document scanner app: no card entry, no rounded corners row device / simulator

Kotlin, the iOS canvas drawing and the preview cannot run under Vitest (native imports): manual checks only.

Additional context
Related ideas from #439, tracked separately: remember PDF export settings per card; card-shaped camera frame for auto scan.

Dominant language
C++
Stars
2.7k
Forks
153
Avg merge
9h 34m
Merged PRs (30d)
123

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ossappscollective/OSS-DocumentScanner

All issues in ossappscollective/OSS-DocumentScanner

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.