Skip to content

Fix decimal separator using invariant culture#31

Open
mdelanno wants to merge 1 commit into
DomCR:masterfrom
mdelanno:fix/invariant-culture-decimal-separator
Open

Fix decimal separator using invariant culture#31
mdelanno wants to merge 1 commit into
DomCR:masterfrom
mdelanno:fix/invariant-culture-decimal-separator

Conversation

@mdelanno

@mdelanno mdelanno commented Jun 6, 2026

Copy link
Copy Markdown

Problem

On a machine using a culture where the comma is the decimal separator (e.g. fr-FR), the exported PDF appears blank in viewers even though the file is full of drawing commands.

The content stream contains numbers formatted with the current culture:

/MediaBox [0 0 471,856 427,000]
...
283,4646 0 l
0,085 w

PDF requires the decimal point as separator, so 283,4646 is parsed as two invalid tokens and the whole content stream is corrupted, rendering nothing.

Fix

Force CultureInfo.InvariantCulture everywhere a double is written to the PDF:

  • PdfPen.toPdfDouble — entity coordinates
  • PdfPen.applyStyle — line width
  • PdfReference<T>.GetPdfForm — MediaBox dimensions (uses IFormattable to stay generic)
  • ColorExtensions.ToPdfString — RGB color components

Note: PdfContent already used the invariant culture for the translation matrix, which is why the bug was easy to miss on en-US machines.

Test

Added a regression test (InvariantDecimalSeparatorTest) that exports a simple document under the fr-FR culture and asserts that no number uses the comma as decimal separator. It restores the previous culture in a finally block.

🤖 Generated with Claude Code

Coordinates, MediaBox dimensions, line weights and RGB colors were
formatted with the current culture. Under a culture that uses the comma
as decimal separator (e.g. fr-FR), this produced numbers like "283,4646"
instead of "283.4646", resulting in an invalid pdf content stream that
viewers render as blank.

Force CultureInfo.InvariantCulture wherever doubles are written:
- PdfPen.toPdfDouble (entity coordinates)
- PdfPen.applyStyle (line width)
- PdfReference<T>.GetPdfForm (MediaBox dimensions)
- ColorExtensions.ToPdfString (RGB color components)

Add a regression test that exports under the fr-FR culture and asserts
that no number uses the comma as decimal separator.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant