本文介绍了为 iTextSharp 罗马尼亚语设置什么编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 iTextSharp 5.5.9.0 版(我从 NuGet 添加)创建一个 PDF 文件.一切正常,但不是罗马尼亚语变音符号 (ȘșȚțăĂÂâ).我阅读了很多有关解决方案的文章,但没有任何效果.现在我建立了一个解决方案,从所有变音符号中只出现 "ăĂÂâ" 其他不出现.这是我的代码:

I try to create a PDF file with iTextSharp version 5.5.9.0 (I added from NuGet). All works fine but not and Romanian diacritics (ȘșȚțăĂÂâ). I read a lot of articles with solutions about that but nothing work. Now I founded a solution that from all diacritics appear only "ăĂÂâ" others not appear.That is my code:

Dim bf As BaseFont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, False)
Dim normalFont As New iTextSharp.text.Font(bf, 9, Font.NORMAL)
Dim par As New Paragraph("ȘșȚțăĂÂâ", normalFont)
pdfDoc.Add(par)

谁能告诉我我必须写什么编码才能拥有所有罗马尼亚语变音符号.

Can anybody write me what encoding I must write to have all Romanian diacritics.

解决方案: 来自Paulo Soares"的说法是正确的.我只做了一些更正.我从这个站点下载了一种支持罗马尼亚语的字体:https://www.fontsquirrel.com/fonts/list/language/romanian/ 比我用编码 BaseFont.IDENTITY_H 在 myBaseFont 上加载它代码如下:

Solution: from "Paulo Soares" is right. I made only some correction.I downloaded one font that support Romanian language from this site:https://www.fontsquirrel.com/fonts/list/language/romanian/ than I loaded it on myBaseFont with encoding BaseFont.IDENTITY_HHere is the code:

Dim ttfPath As String = "C:\Test\DejaVuSerif.ttf" 'Path to font file
Dim bf As BaseFont = BaseFont.CreateFont(ttfPath, BaseFont.IDENTITY_H, False)
Dim normalFont As New iTextSharp.text.Font(bf, 9, iTextSharp.text.Font.NORMAL)

推荐答案

BaseFont.TIMES_ROMAN 等内置字体没有罗马尼亚语变音符号.你需要一个像times.ttf这样的外部字体:

The built-in fonts like BaseFont.TIMES_ROMANdon't have the Romanian diacritics. You'll need an external font like times.ttf:

Dim bf As BaseFont = BaseFont.CreateFont("c:\windows\fonts\times.ttf", BaseFont.IDENTITY_H, True)

这篇关于为 iTextSharp 罗马尼亚语设置什么编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-08 01:13