[FEATURE REQUEST] Remember PDF export layout per document

Open
#864 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
52/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
android, ios, typescript

Research direction

Start with app/utils/exportUtils.ts and its named helper tests in app/utils/exportUtils.test.ts, then trace persistence through app/services/documents.ts and app/models/OCRDocument.ts. Follow PDF option merging and platform forwarding in app/services/pdf/PDFExporter.ts, app/workers/PDFExportWorker.ts, and app/components/pdf/PDFPreview.svelte. Done means document layouts persist and reset correctly across export paths on Android and iOS, with the stated tests and checks passing.

Written by the indexing model from the issue text.

Description

enhancement

Split out of #439 (idea from the maintainer: "remembering card pdf export settings per card").

📋 Context

PDF layout (paper size, orientation, items per page, margin, color, OCR text) is a single global setting today (ApplicationSettings['default_export_options']), rewritten by the PDF preview on every change. Goal: each document remembers its own layout, so re-exporting a card (A4, 2 per page, margin) needs no re-entry.

Assumptions:

  • Applies to both apps (scanner and cardwallet), when the exported pages all belong to one document (a partial export of one document counts).
  • Only layout keys are stored (paper_size, orientation, items_per_page, page_padding, color, draw_ocr_text). password and jpegQuality are never stored.
  • No saved layout → fall back to the global options. Reset on a document sets its value to null.
  • Synced and backed up with the document (see the compatibility note).

🛠️ Recommended approach

  • New nullable column Document.pdfOptions TEXT (not in extra: avoids the d.extra LIKE search noise and the custom-fields display). Migration follows the addTrashedDate pattern.
  • Options are merged in one place, exportPDFAsync: global ← document pdfOptions ← explicit options. This covers open, share, print, export, bulk export (per document) and the preview export.
  • PDFPreview seeds its options from the same merge and saves layout changes to the document (debounced ~500 ms, flushed on destroy; no modifiedDate bump, no list notify). Reset sets pdfOptions to null.
  • Pure helpers in app/utils/exportUtils.ts: getSingleDocument, pickLayoutOptions, resolvePDFOptions.
  • iOS: forward options through PDFExporter → PDFExportWorker → exporter.export (today iOS ignores them, including jpegQuality/password). Android: black_white must read the merged color.
  • Sync/backup: pdfOptions is written by toJSON only when non-null. Compatibility: an older client importing a synced document that carries pdfOptions fails on the unknown column, so only documents with saved settings are affected. DB_VERSION is not bumped (it would block every document on older clients).
📂 Impacted files
File Action Description
app/services/documents.ts Edit Column in createTables, migration, update() branch (value ? JSON.stringify(value) : null), parse in createModelFromAttributes
app/models/OCRDocument.ts Edit pdfOptions field/type; toJSON writes it only when non-null
app/utils/exportUtils.ts Edit getSingleDocument, pickLayoutOptions, resolvePDFOptions
app/utils/exportUtils.test.ts Edit Unit tests
app/services/pdf/PDFExporter.ts Edit Merge options; Android black_white from merged color; pass options to the iOS worker
app/workers/PDFExportWorker.ts Edit Accept and forward options
app/services/pdf/PDFCanvas.ts Edit Optional document seed for options
app/components/pdf/PDFPreview.svelte Edit Seed, debounced per-document save, Reset to null

No new i18n key (the layout sheet is reused).

📝 Steps
  1. Helper tests first (red), then the helpers in exportUtils.ts (green).
  2. Column, migration, model field, update() null/JSON branch, parse, toJSON (non-null only).
  3. Merged options in exportPDFAsync (Android) and forwarded to the iOS worker.
  4. PDFPreview: seed, debounced save, Reset to null. yarn svelte-check + eslint on changed files.
  5. Manual run on both platforms.
🧪 Test strategy
Type Scenario File
Unit getSingleDocument: one doc → that doc; two docs / empty → undefined app/utils/exportUtils.test.ts
Unit pickLayoutOptions drops password and jpegQuality app/utils/exportUtils.test.ts
Unit resolvePDFOptions: null → global; override beats global; explicit beats override app/utils/exportUtils.test.ts
Unit update() with pdfOptions: null stores SQL NULL, not "null"; toJSON omits null pdfOptions next to documents.ts / model (vi.mock NS imports)
Manual Set A4, 2 per page, margin on a card; reopen preview → pre-filled; Export/Share/Print without preview use it; partial export too; another document still uses global; Reset → global. Android + iOS —

Refs #439

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.