我正在创建一个使用iText7的pdf格式。我想要显示罗马数字。你能告诉我我应该使用哪种字体类型吗?我试过使用与罗马数字相当的unicode,比如"\u2162“== III,但在pdf上什么也不显示。
我使用iText7的默认字体。没有添加任何特定的字体类型。哪种字体是罗马数字的字体?
任何指针都会很有帮助。
谢谢
发布于 2018-02-18 12:08:14
我建议使用拉丁大写字母(I,V,X,L,C,D,M)来代表罗马数字,如果你想在你的standard 14 fonts中使用的话。
如果您想使用unicode罗马数字,就像Samuel Huylebroeck和mkl注释的那样,您需要包含unicode罗马数字的字体,并将其与unicode字体编码PdfEncodings.IDENTITY_H一起使用。
以下是使用标准字体和Open Source unicode font的c#示例
const string Latin = "The movie Saving Private Ryan was released in MCMXCVIII.";
const string Unicode = "The movie Saving Private Ryan was released in \u216F\u216D\u216F\u2169\u216D\u2167.";
const string Dest = @"C:\publish\RomanNumerals.pdf";
const string Font = @"C:\fonts\mplus-1p-regular.ttf";
using (var fileStream = new FileStream(Dest, FileMode.Create))
{
var pdfDoc = new PdfDocument(new PdfWriter(fileStream));
using (var doc = new Document(pdfDoc))
{
PdfFont f1 = PdfFontFactory.CreateFont(StandardFonts.HELVETICA);
PdfFont f2 = PdfFontFactory.CreateFont(Font, PdfEncodings.IDENTITY_H);
doc.Add(new Paragraph(Latin).SetFont(f1));
doc.Add(new Paragraph(Unicode).SetFont(f2));
}
}https://stackoverflow.com/questions/48796774
复制相似问题