Fix decimal separator using invariant culture#31
Open
mdelanno wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
PDF requires the decimal point as separator, so
283,4646is parsed as two invalid tokens and the whole content stream is corrupted, rendering nothing.Fix
Force
CultureInfo.InvariantCultureeverywhere adoubleis written to the PDF:PdfPen.toPdfDouble— entity coordinatesPdfPen.applyStyle— line widthPdfReference<T>.GetPdfForm— MediaBox dimensions (usesIFormattableto stay generic)ColorExtensions.ToPdfString— RGB color componentsNote:
PdfContentalready 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 thefr-FRculture and asserts that no number uses the comma as decimal separator. It restores the previous culture in afinallyblock.🤖 Generated with Claude Code