1

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

boilers222
  • 1,901
  • 7
  • 33
  • 71
  • "Justification" does not change font size. But it's safe to say it's Word here which is lying to you. Word, ancient behemoth as it is, still uses large portions of *local printer settings* to format its text, which is why text in a Word document opened on another computer may run different. So your 10 pt text in Word may not end up that size in a PDF. That behavior is kind of hard to copy. – Jongware Apr 07 '16 at 20:20

1 Answers1

0

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.

russw_uk
  • 1,267
  • 8
  • 10