[repo] V1.1: PDF compress presets, PDF to Word, licence check #2

Open
mnovak wants to merge 0 commits from feature/v1-1 into main
Owner

Day 2 (V1.1) of the core: PDF compress presets and PDF to Word, as worker operations, plus the licence check required by Day 2 test 3. The brief is the app repo's docs/roadmap.md (Prompt 2). The app's day page is docs/02_v1-1.md. Formats and the library choice per operation are in docs/FORMATS.md.

What is in it

  • Compress (crates/pdf/src/compress.rs, worker pdf.compress). Three presets: E-mail (target ≤ 5 MB, stepping down 120 → 96 → 72 dpi), Web (150 dpi) and Print (300 dpi).
    • Images are capped at the largest page side × the preset's dpi and re-encoded as JPEG.
    • Streams are Flate-compressed, objects are pruned, and object and xref streams are used.
    • Text, fonts and vectors are untouched, so all text stays extractable.
    • A protected PDF stays protected with the same password.
    • It never hands back a bigger file.
  • PDF to Word (crates/pdf/src/word.rs, worker pdf.to_word, pdf.page_png).
    • pdfium's characters (box, size, weight, slant) are rebuilt into lines, wrapped paragraphs, tables (aligned segments), headings (measured against the body size) and images at their place. docx-rs (MIT) writes the file.
    • Scanned pages are reported, and OCR text for them can be passed in (Fundamentum's Lector, through the app).
  • Licences. scripts/deps.mjs now lists every crate in Cargo.lock, for all platforms: 176 crates, none outside the allowed set. --check fails when the table is out of date or a licence is outside the set. scripts/deps.test.mjs tests the SPDX rule.
  • .fabrica/artifex/test.yaml: everything on the Windows runner (pdfium, corpus, cargo test --release, licences).

Tests (146, all green on the head; clippy clean)

  • Compress (5): every preset is smaller, keeps the text and all pages, and renders. The presets are ordered E-mail ≤ Web ≤ Print. E-mail takes a 20 MB+ file to ≤ 5 MB. A plain PDF is left alone. A protected PDF stays protected.
  • Word (3):
    • Every word comes out in reading order: title, headings, a 3-line paragraph joined into one, a 4×3 table, the image, page two after a page break.
    • Heading styles: Heading1 at least once, Heading2 at least three times.
    • A scan is reported and takes OCR text.
    • LibreOffice 25 converts the .docx back to text with every word in order.
  • Day 1 suites: all unchanged and green.

Self-review: what is weak or not done

  • Compress does not subset fonts. The brief says "where safe". A PDF whose weight is embedded fonts barely shrinks; the result says so.
  • Compress estimates resolution from the largest page side, not from each image's placement. A small logo on a big page keeps its pixels (it is already small).
  • Compress leaves some images as they are: JPEG 2000, CCITT, JBIG2, indexed, 16-bit and CMYK JPEG. Soft masks are never touched.
  • Word follows one column. Two-column layouts are read row by row, so lines from both columns interleave. That is a real gap for newsletters.
  • Word heading detection is by size against the body size: 1.8× → H1, 1.25× → H2, bold, short and slightly larger → H3. Documents that use colour for headings get plain paragraphs.
  • Word table detection needs the column starts to line up. Tables with wrapped cells or merged cells become paragraphs.
  • Word font names are not carried (Calibri throughout); sizes, bold and italic are.
  • "Opens in Scriptum" is tested in the private app repo, because Prelum (Scriptum's engine) is private: src-tauri/tests/word_scriptum.rs there.
  • The LibreOffice test waits for the output file, because a fresh profile's first start exits 1 while it still converts.
Day 2 (V1.1) of the core: PDF compress presets and PDF to Word, as worker operations, plus the licence check required by Day 2 test 3. The brief is the app repo's `docs/roadmap.md` (Prompt 2). The app's day page is `docs/02_v1-1.md`. Formats and the library choice per operation are in `docs/FORMATS.md`. ## What is in it - **Compress** (`crates/pdf/src/compress.rs`, worker `pdf.compress`). Three presets: E-mail (target ≤ 5 MB, stepping down 120 → 96 → 72 dpi), Web (150 dpi) and Print (300 dpi). - Images are capped at the largest page side × the preset's dpi and re-encoded as JPEG. - Streams are Flate-compressed, objects are pruned, and object and xref streams are used. - Text, fonts and vectors are untouched, so all text stays extractable. - A protected PDF stays protected with the same password. - It never hands back a bigger file. - **PDF to Word** (`crates/pdf/src/word.rs`, worker `pdf.to_word`, `pdf.page_png`). - pdfium's characters (box, size, weight, slant) are rebuilt into lines, wrapped paragraphs, tables (aligned segments), headings (measured against the body size) and images at their place. docx-rs (MIT) writes the file. - Scanned pages are reported, and OCR text for them can be passed in (Fundamentum's Lector, through the app). - **Licences.** `scripts/deps.mjs` now lists every crate in Cargo.lock, for all platforms: 176 crates, none outside the allowed set. `--check` fails when the table is out of date or a licence is outside the set. `scripts/deps.test.mjs` tests the SPDX rule. - **`.fabrica/artifex/test.yaml`**: everything on the Windows runner (pdfium, corpus, `cargo test --release`, licences). ## Tests (146, all green on the head; clippy clean) - **Compress (5):** every preset is smaller, keeps the text and all pages, and renders. The presets are ordered E-mail ≤ Web ≤ Print. E-mail takes a 20 MB+ file to ≤ 5 MB. A plain PDF is left alone. A protected PDF stays protected. - **Word (3):** - Every word comes out in reading order: title, headings, a 3-line paragraph joined into one, a 4×3 table, the image, page two after a page break. - Heading styles: Heading1 at least once, Heading2 at least three times. - A scan is reported and takes OCR text. - LibreOffice 25 converts the .docx back to text with every word in order. - **Day 1 suites:** all unchanged and green. ## Self-review: what is weak or not done - **Compress does not subset fonts.** The brief says "where safe". A PDF whose weight is embedded fonts barely shrinks; the result says so. - **Compress estimates resolution** from the largest page side, not from each image's placement. A small logo on a big page keeps its pixels (it is already small). - **Compress leaves some images as they are:** JPEG 2000, CCITT, JBIG2, indexed, 16-bit and CMYK JPEG. Soft masks are never touched. - **Word follows one column.** Two-column layouts are read row by row, so lines from both columns interleave. That is a real gap for newsletters. - **Word heading detection** is by size against the body size: 1.8× → H1, 1.25× → H2, bold, short and slightly larger → H3. Documents that use colour for headings get plain paragraphs. - **Word table detection** needs the column starts to line up. Tables with wrapped cells or merged cells become paragraphs. - **Word font names are not carried** (Calibri throughout); sizes, bold and italic are. - **"Opens in Scriptum" is tested in the private app repo**, because Prelum (Scriptum's engine) is private: `src-tauri/tests/word_scriptum.rs` there. - **The LibreOffice test** waits for the output file, because a fresh profile's first start exits 1 while it still converts.
mnovak added 4 commits 2026-11-17 00:57:44 +01:00
This branch is already included in the target branch. There is nothing to merge.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feature/v1-1:feature/v1-1
git checkout feature/v1-1
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mnovak/Pictor-public#2