简体   繁体   English

您如何证明SharpPDF中的段落合理?

[英]How do you justify a paragraph in sharpPDF?

I have a asp.net MVC project that uses sharpPDF ( http://sharppdf.sourceforge.net/ ) to create PDFs. 我有一个使用SharpPDF( http://sharppdf.sourceforge.net/ )创建PDF的asp.net MVC项目。 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). 有20多个使用SharpPDF编写的PDF,因此在此阶段可能无法切换到另一个PDF生成器(并且我们的客户不太可能为任何PDF软件的付费版本付费)。 The client wants the PDF that's generated to look exactly like the original Word document. 客户希望生成的PDF看起来与原始Word文档完全一样。 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). 尽管使用相同的字体和字体大小,但在Word版本中字母似乎略小一些(Arial Narrow Bold,10)。 Turns out, the Word document justified the paragraph. 原来,Word文档对段落进行了说明。 I can't find a justify option for sharpPDF (only left, right, center). 我找不到SharpPDF的对齐选项(仅左,右,居中)。 How do I justify a paragraph in sharpPDF? 如何证明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): 这是Word(上)和SharpPDF(下)生成的PDF中文本的比较:

在此处输入图片说明

Here are the settings for Word compared to the settings in sharpPDF: 与SharpPDF中的设置相比,这是Word的设置:

在此处输入图片说明

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. 在查看SharpPDF的API时,它没有提供足够低级的接口来允许您自己在该库的顶部实现对齐。

PDFSharp is another free (MIT licensed) library which does support text justification. PDFSharp是另一个免费(由MIT许可)的库,它支持文本对齐。 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. 我意识到您不想进行整体更改,但是如果它只是需要对齐文本的内容的子集,则一个选择是使用PDFSharp生成需要对齐文本的部分,然后使用该库将两者结合起来文件。 Having said that, the API is fairly similar and a port probably would not take long. 话虽如此,API还是非常相似,并且端口可能不会花很长时间。

Another option would be to make use of SharePoint Server if your client has it, to perform the conversion for you. 另一个选择是,如果您的客户端拥有SharePoint Server,则可以使用它来为您执行转换。 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. 与使用自定义代码可以呈现的任何内容相比,这可能会产生更接近原始Word文档的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM