【问题标题】:Itext7: Display roman numbersItext7:显示罗马数字
【发布时间】:2018-02-14 21:46:44
【问题描述】:

我正在使用 iText7 创建一个 pdf。我想显示罗马数字。你能告诉我我应该使用哪种字体类型吗?我尝试使用 unicode 等价于罗马数字,如 "\u2162" == III,但它在 pdf 上没有显示任何内容。

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

任何指针都会有所帮助。

谢谢

【问题讨论】:

  • 您使用的字体可能不包含罗马数字所需的字形。使用 FontForge 之类的东西来检查字体。还要添加您用于加载的相关 iText7 代码并将字体分配给此票证的文本,您将更容易获得答案。
  • 更新了帖子。我正在使用 iText7 的默认字体
  • 默认字体没有帮助:使用标准 14 种字体之一作为默认字体。每个 pdf 查看器都必须支持这些字体,但仅限于有限的字符集,实际上是 WinAnsiEncoding 加上很少的添加。罗马数字的显式字形不在其中。

标签: fonts itext7 roman-numerals


【解决方案1】:

如果您想在 PDF 中使用 standard 14 fonts 之一,我建议您使用拉丁文大写字母 (I V X L C D M) 来表示罗马数字。

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

以下是使用标准字体和Open Source unicode font 示例:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多