C# WPF - Printing - PadRight adds the correct amount of characters while debugging, but in the printout, the whitespaces vary

StackOverflow https://stackoverflow.com/questions/22747521

  •  24-06-2023
  •  | 
  •  

Pregunta

My datastructure contains employees and their hours of work for every day (the rest of the datastructure is irrelevant for the problem).

I want to print a document that displays the working times for every employee in the selected week. In order to format the document, I use PadRight to fill the employee-name with blanks, so I have one column with only employees and one with the working hours.

the following code-segment shows the code that is necessary to print one 'employee-time'-line, so the flowdocument and paragraph will not be included

string empName = employee.name.PadRight(150);
string time = employee.startTime.toShortTimeString().PadLeft(7);
myParagraph.Inlines.Add("\t"+empName+" - "+time);

While debugging, the variable "empName" has the correct length of 150 characters and "time" is 7 characters long.

When I print the document, the Padding gets messed up and every line has the exact same amount of blanks instead of 150-employee.name.length.

I've tried string.Format() aswell, that did the same thing. correct length while debugging, wrong length on the printout.

The tab ("\t") is not cause of the problem, it doesn't work either when I take it out of the code


tl;dr: im printing a string.PadRight(150) and on the printout, the padright doesnt work properly


finally the question: how the hell do i get that stupid flowdocument to insert the correct number of blanks?

Thank you for reading and for potential help

¿Fue útil?

Solución

solved. The problem was not WPF, but the XPS-Printer. Formatting was completely okay when I printed an actual document on an actual printer

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top