omega-pdf
opdf reads PDF files and copies pages between them. It is written only in seeded Omega and built by the pinned compiler (see PIN). It is written from the public standard ISO 32000-1:2008 (PDF 1.7); each rule's clause is cited in the source. No vendor program was disassembled or copied.
opdf info FILE.pdf version, page count, encryption, cross-reference and object streams, Info strings
opdf pages FILE.pdf per page: index, MediaBox (inherited, 7.7.3.4), Rotate, number of content streams
opdf text FILE.pdf [FIRST LAST] the text of the pages, in content-stream order
opdf split FILE.pdf FIRST LAST OUT.pdf
opdf merge OUT.pdf A.pdf [B.pdf ...]
text prints text in the order the content streams draw it. This is the reading order as written in the file, not layout analysis: no columns, no sorting, no dehyphenation.
- A newline is printed when the text position moves across the baseline by more than 0.5 times the effective font size.
- One space is printed when it moves along the baseline by at least 0.12 times the effective font size beyond the end of the previous glyph.
- Each page ends with LF then FF.
Unicode comes from the font's ToUnicode CMap (bfchar, bfrange in both forms, UTF-16 surrogates, multi-character destinations) when present (9.10.3). Otherwise it comes from the simple font's Encoding: StandardEncoding, WinAnsiEncoding, MacRomanEncoding and Differences with the Latin glyph names. The table is ISO 32000-1 Annex D.2/D.3, kept as data in src/text.om.
split and merge write a new file. It holds the selected pages and every object they reach: resources, fonts, and content and image streams copied byte for byte with no re-encoding. It also has a fresh page tree and catalog, the effective MediaBox/CropBox/Resources/Rotate written on each page, a classic cross-reference table and a trailer.
Build
cat src/head.om vendor/omega-zip/vendor/omega-mv/seed/text/text.om vendor/omega-zip/src/io.om vendor/omega-zip/src/crc32.om vendor/omega-zip/src/inflate.om vendor/omega-zip/src/zlibd.om src/core.om src/text.om src/writer.om src/main.om | OMC > opdf && chmod +x opdf
OMC is omega-mv 82e536e1 seed/out/omc, sha256 6d1b1cf5a44803389a831b67f750ea4cd1c9f53edfde9d6d9241d7352887f1f8. FlateDecode uses omega-zip's inflate at 28e91f99, vendored with S2's one-line sink.patch (vendor/omega-zip/PIN in omega-office records the hashes). src/core.om defines the wout sink.
Gate
OMC < tests/gate.om > build/gate-bin && chmod +x build/gate-bin && build/gate-bin OMC
The gate prints OPDFGATE PASS cases=N mutants-killed=K/K robust-runs=R, exit 0. It prints NOT_RUN and exits 3 when the compiler is not the pin. It runs installed oracles as test-only tools, never shipped: pdfinfo and pdftotext 24.02.0 (their outputs are recorded in corpus/expect), Ghostscript 10.02.1 (-dPDFSTOPONERROR -dPDFSTOPONWARNING -sDEVICE=nullpage, run live on every split and merge output as the structure checker), and pdftotext live on those outputs. qpdf and mutool are not installed. The corpus is described in corpus/SOURCES.txt, made by LibreOffice 24.2.7.2, pdfTeX 1.40.25 and tests/mkcases.om, with oracle verdicts in corpus/ORACLE.txt.
Before the cases the gate builds tests/docs.om with the same compiler and runs it: publication checks of the repository's own text. Its rules (tests/docrules.txt) refuse local home paths, a source or README note citing a file outside the repository or missing from it, a note leaving a question open, a missing licence, and a sentence saying an exit code has no case when tests/cases.txt has one. It prints DOCS PASS ... mutants-killed=K/K (its own mutants, tests/docmutants.txt, each putting back a defect bay 7 found at 9b4164be); any other result fails the gate.
Text comparison normalisation:
- Every run of ASCII whitespace (including LF and FF) becomes one space, and leading and trailing whitespace is removed.
- U+FB00..U+FB04 are expanded to ff/fi/fl/ffi/ffl on both sides.
Difference classes against the oracles:
- Line structure and trailing blanks. pdftotext places line breaks by its own layout rules. On the rotated pdfTeX page it breaks after every word, and it drops trailing spaces. These are removed by the whitespace normalisation.
- Ligatures. Annex D maps the glyph names fi and fl to U+FB01 and U+FB02. pdftotext expands them. Removed by the ligature expansion.
- Info strings that are not ASCII.
infoprints strings raw, with bytes outside printable ASCII as\xHH; pdfinfo decodes UTF-16 and PDFDocEncoding. These values are not compared and are counted as info-strings-not-compared. - Glyph names outside Annex D (for example ff, ffi, dotlessj in pdfTeX T1 fonts). pdftotext resolves them through the Adobe Glyph List; opdf prints U+FFFD. No corpus page shows such a code.
- Symbolic fonts without Encoding or ToUnicode. Only Differences codes are mapped; other shown codes print U+FFFD, because the font program's built-in encoding is not read.
- Standard-14 fonts without Widths. Spacing uses MissingWidth or 500/1000 em, so spaces may differ (none in the corpus).
- Repairs. pdftotext and Ghostscript repair damaged files: bad startxref, xref offsets, Prev cycles, missing endstream. opdf refuses them, because reconstruction is not in this slice.
Exit codes
| Code | Meaning |
|---|---|
| 0 | done |
| 1 | usage, or page range outside the document |
| 2 | cannot open the input |
| 5 | cannot create the output (it must not exist already; exclusive creation) |
| 3 | read error inside the vendored inflate input (pread) |
| 10..21 | DEFLATE stream errors (omega-zip S1 codes) |
| 30 | bad zlib header |
| 31 | zlib preset dictionary |
| 32 | Adler-32 mismatch |
| 60 | malformed PDF: startxref, cross-reference data, object header, stream Length/endstream, page tree. No reconstruction |
| 61 | encrypted (trailer Encrypt). Not supported in this slice |
| 62 | unsupported filter or predictor for that stream: LZW, RunLength, DCT, JBIG2, CCITT, JPX, Crypt, external (F) stream data, TIFF predictor. Only jobs that need that stream are refused |
| 63 | a bound or structural cycle (page-tree cycle, Prev cycle, reference chains, nesting, sizes, work) |
| 64 | I/O error (read, seek, or stdout write) |
| 65 | text: unsupported font or CMap (CID font without ToUnicode, any CID Encoding other than Identity-H, vertical writing, form XObjects and inline images carrying text) |
| 66 | text: malformed content stream, font or CMap |
| 67 | split/merge: an object that cannot be copied (a reference to an ObjStm or XRef stream itself, external stream data, a duplicate page, a direct stream) |
| 68 | split/merge: write error on the output |
Refusal cases in the gate cover 1, 2, 5, 10..21, 30..32, 60, 61, 62, 63, 64 (a directory as input), 65, 66 and 67. Codes 3 and 68 have no case: a regular file cannot make pread or pwrite fail without fault injection.
Bounds (each refused with its code, never a trap)
- Object numbers 65535; parsed nodes 262143; object stream objects 65536; cross-reference sections in a Prev chain 1024 (63).
- Container nesting 64; reference chain and object-load depth 64; decode/filter depth 64.
- Names 256 bytes; strings 65536 bytes; numeric tokens 128 bytes.
- Decoded stream held in memory 16 MiB (content streams, CMaps, object streams, xref streams); decoded-byte pool 16 MiB.
- Pages 4096 per input; page-tree depth 64; work 100000000 lexical/output steps per run.
- Text: operands 4096, operand bytes 1 MiB, literal-string nesting 256, q/Q depth 32, 4096 font loads per page, ToUnicode 65536 entries with 512 bytes per destination, 64 codespace ranges, text per page 16 MiB.
- Writer: 65535 output objects, 65535 output pages, 4095 inputs, 4194304 copy steps per input and pass, output at most 9999999999 bytes (10-digit xref offsets).
Static buffers only: there is no heap.
Not supported in this slice
Encryption; LZW, RunLength and image-filter decoding (DCT, JBIG2, CCITT, JPX), though image streams are copied untouched by split and merge; CID fonts without ToUnicode; vertical writing; layout analysis; forms (AcroForm) and text inside form XObjects; annotations (pages are copied with their Annots, and references to pages that are not copied become null); incremental-update writing; linearization on output; damaged-file reconstruction.
Next slice
A real writer for new PDFs: content-stream generation, fonts (embedding a subset with Widths and ToUnicode), compression on output (needs a deflate compressor, which does not exist in Omega yet), plus the Annex D Symbol/ZapfDingbats sets and reading font programs' built-in encodings.
Caveat
If an input changes between the writer's preflight pass and its copy pass and its zlib data then fails, a partial OUT can remain. The exit status is non-zero (10..32).