How do you justify a paragraph in sharpPDF?

339 Views Asked by At

I have a asp.net MVC project that uses sharpPDF (http://sharppdf.sourceforge.net/) to create PDFs. There are 20+ PDFs written using sharpPDF, so switching to another PDF generator probably isn't possible at this stage (and our client is unlikely to pay for a paid version of any PDF software). The client wants the PDF that's generated to look exactly like the original Word document. The letters seem to be just a little smaller in the Word version despite using the same font and font size (Arial Narrow Bold, 10). Turns out, the Word document justified the paragraph. I can't find a justify option for sharpPDF (only left, right, center). How do I justify a paragraph in sharpPDF? Alternatively, how to I get the text to look like it's justified?

Here is a comparison of the text in Word (top) and in my PDF generated by from sharpPDF (bottom):

enter image description here

Here are the settings for Word compared to the settings in sharpPDF:

enter image description here

1

There are 1 best solutions below

0
On

Looking at the API for SharpPDF it doesn't expose a sufficiently low level interface to allow you to implement the justification yourself on top of that library.

PDFSharp is another free (MIT licensed) library which does support text justification. I realise that you don't want to do a wholesale change, but if it's only a subset of the content that requires justified text one option would be to generate the sections that require justified text using PDFSharp and then use the library to combine the two documents. Having said that, the API is fairly similar and a port probably would not take long.

Another option would be to make use of SharePoint Server if your client has it, to perform the conversion for you. This is likely to produce something closer to the original word document than anything you're likely to be able to render using custom code.