{"record":{"id":"24f56394438bc993","repo":"iOfficeAI/OfficeCLI","slug":"keyname-must-be-in-range-pagedimmintwips-page","errorCode":null,"errorMessage":"{keyName} must be in range {PageDimMinTwips}–{PageDimMaxTwips} twips (~0.4cm–55.9cm), got {twips}.","messagePattern":"(.+?) must be in range (.+?)–(.+?) twips \\(~0\\.4cm–55\\.9cm\\), got (.+?)\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/WordPageDefaults.cs","lineNumber":27,"sourceCode":"/// must always read the source <c>SectionProperties</c> first and only\n/// drop to these defaults when the value is genuinely absent.\n/// </summary>\npublic static class WordPageDefaults\n{\n    // A4: 210mm × 297mm at 1440 twips/inch (= 567 twips/cm).\n    public const uint A4WidthTwips = 11906;\n    public const uint A4HeightTwips = 16838;\n\n    // OOXML legal range for w:pgSz/@w:w and @w:h. Word's UI clamps roughly to\n    // ~0.4cm–55.9cm; the EcmaSpec defines 1..31680 (22\"). Use 240 (1/6\") as the\n    // lower bound — anything smaller will not produce a renderable page in Word.\n    public const uint PageDimMinTwips = 240;\n    public const uint PageDimMaxTwips = 31680;\n\n    public static void ValidatePageDim(long twips, string keyName)\n    {\n        if (twips < PageDimMinTwips || twips > PageDimMaxTwips)\n            throw new ArgumentException(\n                $\"{keyName} must be in range {PageDimMinTwips}–{PageDimMaxTwips} twips \" +\n                $\"(~0.4cm–55.9cm), got {twips}.\");\n    }\n}\n","sourceCodeStart":9,"sourceCodeEnd":32,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/WordPageDefaults.cs#L9-L32","documentation":"Thrown by WordPageDefaults.ValidatePageDim when a page width/height (w:pgSz/@w:w or @w:h) is outside the OOXML-legal range 240..31680 twips (~0.4cm..55.9cm). The lower bound 240 (1/6 inch) is the smallest that produces a renderable page in Word; the upper bound 31680 (22 inch) is the EcmaSpec max. Values outside this range are rejected rather than clamped.","triggerScenarios":"Setting page width/height (pageWidth/pageHeight or section pgSz) to a value below 240 twips or above 31680 twips; e.g. a near-zero size, or a very large custom page; replaying a doc with a corrupt pgSz.","commonSituations":"Unit confusion (passing points/cm where twips expected, or vice-versa); a corrupt source document with a garbage pgSz; an automation layer computing geometry incorrectly.","solutions":["Provide a page dimension in 240..31680 twips (e.g. A4 = 11906 x 16838 twips).","Double-check units: 1 inch = 1440 twips, 1 cm = 567 twips, 1 pt = 20 twips.","If the value came from another unit, convert correctly before passing twips."],"exampleFix":"// before: passed points as if twips -> far below 240\nWordPageDefaults.ValidatePageDim(21, \"pageWidth\");  // 21 twips ~ 0.015 inch\n// after: convert cm -> twips (1cm = 567 twips)\nWordPageDefaults.ValidatePageDim((long)Math.Round(21.0 * 567), \"pageWidth\"); // A4 width","handlingStrategy":"validation","validationCode":"static bool IsValidPageDim(long twips)\n    => twips >= WordPageDefaults.PageDimMinTwips && twips <= WordPageDefaults.PageDimMaxTwips;","typeGuard":null,"tryCatchPattern":"try { WordPageDefaults.ValidatePageDim(twips, keyName); }\ncatch (System.ArgumentException ex) when (ex.Message.Contains(\"twips\"))\n{ /* clamp into range or report the accepted range to the user */ }","preventionTips":["Convert cm/inch/pt to twips with the right factor before validating.","Use the A4/Letter constants as safe defaults."],"tags":["word","validation","page-setup","units"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}