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:

http://www.pdfsharp.net/wiki/MigraDocHelloWorld-sample.ashx

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:
https://stackoverflow.com/a/19301602/1015447

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