Skip to content

Printing from WPF is leaving random small spaces in the text when using Arial or Calibri fonts #7499

@campeters

Description

@campeters

Description

When printing in WPF, the graphics engine is inserting small spaces within words. For instance, the French word 'fonctions' is printed either as 'fonction s' or 'fo nctions' depending on where the word appears within the other text.

Reproduction Steps

public void PrintItAll()
        {
            var printDialog = new PrintDialog();
            if (printDialog.ShowDialog() == true)
            {
                var fontFamily = new FontFamily("Arial");
                var printme = new TextBlock {
                    FontSize = 11, FontFamily = fontFamily, Width = 800, TextWrapping = TextWrapping.Wrap,
                    Text = "L'autre personne était incapable de prendre soin des enfants en raison d'une déficience des fonctions physiques ou mentales qui l'a obligée, durant une période d'au moins deux semaines, à garder le lit, à se déplacer en fauteuil roulant ou à recevoir des soins dans un hôpital ou un établissement semblable. Joignez un certificat du médecin traitant qui confirme la nature et la durée de la déficience."
                };
                printDialog.PrintVisual(printme, "Test Print");
            }
        }

Reproduction repository: https://github.com/campeters/Wpf-Print-Font-Issue

Expected behavior

The text should print correctly without extra spaces.

Actual behavior

The following file shows a space between 'fonction' and the 's'. It should be a single french word 'fonctions'

Test Print.pdf

Regression?

This code works correctly in dot net framework and it also seems to work correctly in .net 5.

Known Workarounds

None.

Impact

This bug impacts the quality of PDF and print files generated from WPF programs using the 'Arial' or 'Calibri' fonts. Some fonts work correctly. However, the filing of some government forms require that only 'Arial' be used.

Configuration

This bug occurs in .net 6, confirmed in 6.0.11 and 6.0.13 and .net 7. It does not appear to be specific to the configuration. It happens on Windows 10 and Windows 11.

The exact same code works correctly in .net framework 4.8.1

Other information

No response

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions