Brandon Avant Brandon Avant - 3 years ago 105
C# Question

Retaining Tabs in String When Rendering MigraDoc PDF

Basically, I was able to successfully generate a multiple page PDF (from a string read from a .txt file) using the MigraDoc sample here:

The problem is that in the original text there are tabs and whitespace that yields a document with centered text, as well as sections of text separated by spaces. It looks this way in notepad as well as in the string viewer in Visual Studio.

When the PDF is generated, everything is left justified and all of the tabs and extra whitespace has been removed.

Given the sample in the above link, how can I keep the originally white space? It seems like if notepad can render it correctly and the string reads in correctly in C#, the PDF generated should also look exactly the same.

Answer Source

MigraDoc is like HTML: multiple spaces get merged into one space.

To get centred text with MigraDoc, just set the paragraph to centre alignment. IMHO that is the best way.

To retain multiple spaces in pre-formatted text just replace the spaces with non-breaking spaces.

See also:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download