在ASP.NET C#中将HTML Div(带有标签和印地语Unicode)转换为PDF [英] Html Div (with tags and Hindi Unicode) to PDF in asp.net c#

查看:118
本文介绍了在ASP.NET C#中将HTML Div(带有标签和印地语Unicode)转换为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用C#将具有印地语(Unicode字符)内容的HTML <div>导出为ASP.NET中的PDF.我尝试了许多不同的第三方HTML到PDF的转换工具,例如nReco,evopdf,hiqpdf等.它们都无法正常工作,因为它们可能不会显示北印度文,或者不会显示结果文本. t正确呈现.例如,如果我在Unicode中有文本"न्‍यायालय,विरूद्व,डब्‍ल्‍यु",则字符显示不正确.

i want to export HTML <div> with content in Hindi (Unicode characters) to PDF in ASP.NET using C#. I've tried many different third party HTML to PDF conversion tools, such as nReco, evopdf, hiqpdf,... None of them are working properly in the sense that the Hindi text either isn't shown, or the resulting text isn't rendered correctly. For instance, if I have the text "न्‍यायालय,विरूद्व,डब्‍ल्‍यु" in Unicode, the characters are rendered incorrectly.

推荐答案

我创建了一个HTML文件devanagari.html:

I created an HTML file devanagari.html:

<body>
<div>न्‍यायालय,विरूद्व,डब्‍ल्‍यु</div>
</body>

然后我使用 iText 7 + pdfHTML插件 +

And I converted this file to PDF using iText 7 + the pdfHTML add-on + the pdfCalligraph add-on.

您可以在以下屏幕截图中看到结果:

You can see the result in the following screen shot:

要完成这项工作,我首先加载了iText 7许可证密钥以激活iText 7和twoo附加组件:

To make this work, I first loaded my iText 7 license key to activate iText 7 and the twoo add-ons:

LicenseKey.loadLicenseFile(System.getenv("ITEXT7_LICENSEKEY") + "/itextkey.xml");

在C#中,您需要类似以下内容(请参见

In C#, you'd need something like this (see How do I load a license key?):

LicenseKey.LoadLicenseFile("path/to/itextkey.xml");

然后我运行以下代码:

HtmlConverter.convertToPdf(new File(src), new File(dest));

在C#中,这类似于:

HtmlConverter.ConvertToPdf(src, dest);

其中src是指您的HTML,dest是所生成的PDF.

where src refers to your HTML, and dest to the resulting PDF.

据屏幕截图显示,内容正确呈现.大多数其他工具将以这种方式呈现文本(如果它们可以呈现任何内容):

As far as I can tell from the screen shot, the content is rendered correctly. Most other tools will render the text like this (if they render anything at all):

很明显,这是不正确的,因为没有进行连字.

Obviously, that is incorrect because no ligatures were made.

有关使用iText将HTML转换为PDF的更多信息,请查阅

For more info about converting HTML to PDF with iText, please consult the HTML to PDF tutorial. For instance: if you want to use a different font than the default font that is shipped with pdfHTML (FreeSans), you should consult chapter 6: Using fonts in pdfHTML.

这篇关于在ASP.NET C#中将HTML Div(带有标签和印地语Unicode)转换为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆