Page geometry and the single
opts.pdfoption validator.
Module oconvPdfBox | Source packages/front/office/oconv/src/write/pdf/box.js | Deps — none | Worker-safe yes
Resolve
import { ModuleRuntime } from '@awacloud/fw/core/runtime.js';
import { fw_require, modules } from '@awacloud/oconv';
const runtime = new ModuleRuntime();
runtime.registerAll(fw_require);
runtime.registerAll(modules);
const oconvPdfBox = runtime.resolve('oconvPdfBox');
Composed internally by ir-to-pdf, which forwards the
WHOLE opts.pdf block here so option validation lives in exactly ONE
place; resolving it directly is for validating or previewing a layout in
isolation.
API
| Member | Signature | Returns | Throws |
|---|---|---|---|
PAGE_SIZES |
object |
{A4: [595.276, 841.89], Letter: [612, 792]} (points) |
— |
DEFAULTS |
object |
the frozen default option block | — |
resolveLayout |
(pdfOpts?: object) => Layout |
frozen Layout |
Error oconv: bad pdf option <key> |
Layout members: pageWidth/pageHeight (media box, pt), margin
(uniform, pt), column (pageWidth − 2·margin), contentHeight
(pageHeight − 2·margin), baseSize (pt), codeSize (pt), pageNumbers
(boolean), leading(sizePt) (baseline-to-baseline distance =
leadingRatio · sizePt), sizeFor(kind, level?) ('heading' →
headingScale[level−1], 'code' → codeSize, else baseSize).
Examples
Resolve the default layout, and reject an unknown key
const layout = oconvPdfBox.resolveLayout();
layout.column; // 481.89 (595.276 − 2·56.693)
layout.contentHeight; // 728.504
layout.leading(11); // 14.520000000000001 (1.32 × 11, floating point)
layout.sizeFor('heading', 1); // 22
layout.sizeFor('code'); // 9.5
try {
oconvPdfBox.resolveLayout({ bogus: true });
} catch (e) {
e.message; // 'oconv: bad pdf option bogus'
}
Executed against the live package (2026-10-06): values exactly as shown
above, e.message === 'oconv: bad pdf option bogus'.
Notes
fontsis accepted-and-ignored here (FORWARDED_KEYS): it carries the caller's embedded font bytes and is consumed bypdf/metrics.createMeasurer({fonts})(the embedded-font route), not by geometry. Listing it here is what lets the facade forward ONE object to ONE validator — every other key outsideDEFAULTSthrows.- Full
opts.pdftable (key, type, default, exact error literal) is onpdf-writer.md— restated in their-to-pdfAPI section too; not duplicated a third time here. marginvalidation is BOTH a lower bound (≥ 0) and an upper bound tied to page size (2·margin < min(pageWidth, pageHeight)) — a margin that would leave zero or negative column width throwsoconv: bad pdf option margin, not a silent empty column.pageSizeaccepts either a named size ('A4'/'Letter') or an explicit[width, height]pair of positive numbers, in points — anything else (a third array length, a non-positive number, an unknown name) throwsoconv: bad pdf option pageSize.- Pure module,
dependencies: []: no I/O, no@awacloud/*coupling. Capture-free (fw/no-factory-capture) — every constant is declared in the factory body, so the descriptor survives Worker serialization and the standalone builder'sfactory.toString()inlining.
See also
ir-to-pdf— the sole caller, which forwards the wholeopts.pdfblock here.pdf/metrics— consumes thefontskey this module forwards untouched.pdf/stack— readslayout.leading/layout.sizeFor/layout.column/layout.contentHeightduring flow and page stacking.pdf-writer.md— the audience-facingopts.pdfreference, including every validation error literal.