将Arial Unicode MS添加到CKEditor

rea*_*404 12 pdf unicode fonts flying-saucer ckeditor

我的Web应用程序允许用户在CKEditor中编写富文本,然后使用Flying Saucer库将结果导出为PDF.

由于他们需要编写希腊字符,我选择通过执行以下操作将Arial Unicode MS添加到可用字体:

config.font_names = "*several fonts...*; Arial Unicode MS/Arial Unicode MS, serif";
Run Code Online (Sandbox Code Playgroud)

此字体现在在CKEditor菜单中正确显示,但是当我将此字体应用于任何元素时,我得到以下结果:

<span style="font-family:arial unicode ms,serif;"> some text </span>
Run Code Online (Sandbox Code Playgroud)

你可以注意到,我丢失了UpperCase字符.这在PDF导出期间效果非常糟糕,因为Flying Saucer无法识别字体,因此使用不支持Unicode字符的Helvetica,因此希腊字符不会显示在PDF中.

如果我从代码源手动更改

<span style="font-family:arial unicode ms,serif;"> some text </span>
Run Code Online (Sandbox Code Playgroud)

<span style="font-family:Arial Unicode MS,serif;"> some text </span>
Run Code Online (Sandbox Code Playgroud)

然后按预期工作,显示希腊字符.

以前有人遇到过这个问题吗?有没有办法避免将UpperCase字符更改为LowerCase?我真的想避免做任何类型的后期处理,如:

htmlString = htmlString.replace("arial unicode ms", "Arial Unicode MS");
Run Code Online (Sandbox Code Playgroud)

obo*_*ain 2

我没有找到任何方法可以使用飞碟 R8 实现此目的,但您可以使用飞碟 R9 使其工作。

方法 ITextResolver.addFont(String path, String fontFamilyNameOverride, String encoding, boolean嵌入, String pathToPFB)允许您添加具有特定名称的喜欢。

代码示例:

  ITextRenderer renderer = new ITextRenderer();
  // Adding fonts
  renderer.getFontResolver().addFont("fonts/ARIALUNI.TTF", "arial unicode ms", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, null);
  renderer.getFontResolver().addFont("fonts/ARIALUNI.TTF", "Arial Unicode MS", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, null);

  String inputFile = "test.html";
  renderer.setDocument(new File(inputFile));
  renderer.layout();

  String outputFile = "test.pdf";
  OutputStream os = new FileOutputStream(outputFile);
  renderer.createPDF(os);
  os.close();
Run Code Online (Sandbox Code Playgroud)

您可以在Maven上找到飞碟 R9 。