Html Div (with tags and Hindi Unicode) to PDF in a

2019-06-01 03:09发布

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.

1条回答
地球回转人心会变
2楼-- · 2019-06-01 03:41

I created an HTML file devanagari.html:

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

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:

enter image description here

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");

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

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

Then I ran this line of code:

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

In C#, this would be something like:

HtmlConverter.ConvertToPdf(src, dest);

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):

enter image description here

Obviously, that is incorrect because no ligatures were made.

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.

查看更多
登录 后发表回答