iOfficeAI/OfficeCLI · error · ArgumentException

Invalid font size: '{value}'. Maximum font size is 4000pt (O

Error message

Invalid font size: '{value}'. Maximum font size is 4000pt (Office cap).

What it means

Thrown by ParseFontSize when the size exceeds 4000pt. Office caps user-entered sizes at 1638pt (Word) and renderers stop honoring values past ~4000pt; larger values overflow the int32 the writers cast to (PPTX writes pt*100, Word pt*2 as half-points), producing negative w:sz/a:rPr@sz values Word rejects on open. The library rejects up front rather than emitting corrupt output.

Source

Thrown at src/officecli/Core/ParseHelpers.cs:383

            throw new ArgumentException($"Invalid font size: '{value}'. Comma is not allowed — use '.' as decimal separator (e.g., '10.5').");
        if (!double.TryParse(trimmed, CultureInfo.InvariantCulture, out var result) || double.IsNaN(result) || double.IsInfinity(result))
            throw new ArgumentException($"Invalid font size: '{value}'. Expected a finite number (e.g., '12', '10.5', '14pt').");
        if (result <= 0)
            throw new ArgumentException($"Invalid font size: '{value}'. Font size must be greater than 0.");
        // OOXML w:sz/w:szCs/w:fontSize are half-points and must be >= 1.
        // Anything below 0.5pt would round to val=0 on write, producing
        // schema-invalid OOXML. Reject up front with the same shape as
        // the "<= 0" guard above.
        if (result < 0.5)
            throw new ArgumentException($"Invalid font size: '{value}'. Minimum font size is 0.5pt (one half-point).");
        // OOXML caps user-entered font size at 1638pt (Word) and Office
        // renderers stop honoring values past ~4000pt anyway. Anything
        // larger silently overflows the int32 the writers cast to (PPTX
        // writes pt × 100, Word writes pt × 2 as half-points), producing
        // negative w:sz / a:rPr@sz values Word rejects on open. Reject
        // up front with the same shape as the lower-bound guards.
        if (result > 4000)
            throw new ArgumentException($"Invalid font size: '{value}'. Maximum font size is 4000pt (Office cap).");
        return result;
    }

    /// <summary>
    /// BUG-R4B(BUG1): Leniently parse an integer-valued OOXML attribute that
    /// some producers emit with a fractional part (e.g. <c>w:w="0.0"</c> /
    /// <c>w:w="9440.0"</c>). The Open XML SDK's typed accessors (e.g.
    /// <c>Int32Value.Value</c>) parse the raw string lazily and throw a bare
    /// <see cref="FormatException"/> ("The input string '0.0' was not in a
    /// correct format") the first time the value is read. Reading the raw
    /// <c>InnerText</c> and routing it through this helper truncates the
    /// fractional part to an int (matching Word's own tolerance for these
    /// attributes), so dump/get no longer crash on such files.
    ///
    /// Returns null when <paramref name="raw"/> is null/blank or cannot be
    /// parsed even leniently.
    /// </summary>
    public static int? LenientInt(string? raw)

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Use a size at or below 4000pt.
  2. Clamp: Math.Min(pts, 4000).
  3. Audit code that multiplies sizes to ensure it stays within the Office cap.

Example fix

// before
var pts = halfPoints * 2 * 10; // unintended inflation
ParseFontSize(pts.ToString(CultureInfo.InvariantCulture)); // throws 296

// after
var pts = Math.Min(halfPoints * 2, 4000.0);
ParseFontSize(pts.ToString(CultureInfo.InvariantCulture));
Defensive patterns

Strategy: validation

Validate before calling

const double MaxPt = 4000;
pts = Math.Min(pts, MaxPt);

Type guard

static bool IsWithinOfficeCap(double v) => v <= 4000 && !double.IsNaN(v) && !double.IsInfinity(v);

Try / catch

try { pts = ParseFontSize(s); }
catch (ArgumentException ex) when (ex.Message.Contains("4000pt"))
{ pts = 4000; }

Prevention

When it happens

Trigger: Passing "5000" or a size scaled up by a bug. A unit confusion where points were treated as half-points and doubled.

Common situations: A multiplier bug inflating sizes; feeding a value intended as half-points directly as points; stress-test inputs.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/70a13400827ac674. Report an issue: GitHub.