首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Itext7:显示罗马数字

Itext7:显示罗马数字
EN

Stack Overflow用户
提问于 2018-02-15 05:46:45
回答 1查看 163关注 0票数 1

我正在创建一个使用iText7的pdf格式。我想要显示罗马数字。你能告诉我我应该使用哪种字体类型吗?我试过使用与罗马数字相当的unicode,比如"\u2162“== III,但在pdf上什么也不显示。

我使用iText7的默认字体。没有添加任何特定的字体类型。哪种字体是罗马数字的字体?

任何指针都会很有帮助。

谢谢

EN

回答 1

Stack Overflow用户

发布于 2018-02-18 12:08:14

我建议使用拉丁大写字母(I,V,X,L,C,D,M)来代表罗马数字,如果你想在你的standard 14 fonts中使用的话。

如果您想使用unicode罗马数字,就像Samuel Huylebroeckmkl注释的那样,您需要包含unicode罗马数字的字体,并将其与unicode字体编码PdfEncodings.IDENTITY_H一起使用。

以下是使用标准字体和Open Source unicode fontc#示例

代码语言:javascript
复制
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));
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48796774

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档