【问题标题】:How to I assign the ttf font file in the vfs_fonts.js?如何在 vfs_fonts.js 中分配 ttf 字体文件?
【发布时间】:2017-01-14 05:46:19
【问题描述】:

我正在尝试将自定义字体添加到 vfs_fonts.js 中,但我不明白 window.pdfMake 对象的 value 字段中需要写什么?

我的密钥是“MyFont.ttf”,我知道该值只不过是 ttf 文件。我的 ttf 是一个物理文件,而不是一组字符。如何填写值字段?

 window.pdfMake = window.pdfMake || {}; window.pdfMake.vfs = {
      "Roboto-Italic.ttf": "AAEAAAASAQAABA",
      "Roboto-Medium.ttf": "AAEAAA",
      "MyFont.ttf":"???????????????????"
    }

谢谢

【问题讨论】:

  • 有人能回答这个问题吗?

标签: javascript jquery fonts pdfkit pdfmake


【解决方案1】:
/*  Read the documenation at https://github.com/bpampuch/pdfmake 
specially the readme file */

<!doctype html>
<html lang='en'>
<head>
   <meta charset='utf-8'>
   <title>my first pdfmake example</title>
   <script src='build/pdfmake.min.js'></script>
   <script src='build/vfs_fonts.js'></script>
</head>
<body>

<script>


// works great with the default vfs_fonts.js

   pdfMake.fonts = {
      Roboto: {
         normal: 'Roboto-Regular.ttf',
         bold: 'Roboto-Medium.ttf',
         italics: 'Roboto-Italic.ttf',
         bolditalics: 'Roboto-MediumItalic.ttf'
      }
   };

 // open the PDF in a new window
   pdfMake.createPdf(docDefinition).open();


</script>

</body>

【讨论】:

  • 仅供参考:不要将字体写入、复制、粘贴到 vfs_fonts.js 文件中。
  • 使用 gulp buildFonts 从 ttf 字体文件创建 vfs_fonts.js 文件
猜你喜欢
  • 1970-01-01
  • 2020-12-06
  • 2021-04-22
  • 2018-12-13
  • 2022-10-02
  • 2017-07-14
  • 1970-01-01
  • 2015-08-17
  • 2017-02-08
相关资源
最近更新 更多