使用printJS打印Google字体

时间:2018-12-07 19:59:44

标签: printjs

我已经一起使用printJS和jQuery来打印HTML div的内容。

div包含以“ Annie get your telescope”谷歌字体呈现的文本。

打印时,将使用更标准的Web字体而不是Google字体来打印文本。如果我下载字体并将其托管在本地,则根本看不到任何文本。

如何通过printJS打印HTML并获取Google字体的文本以正确呈现?

1 个答案:

答案 0 :(得分:2)

确保将所需的字体传递给printJS。如果您不使用css属性传递样式表,则只需通过style属性传递字体。

另一件事,当前,print.js设置了用于打印的默认字体,该字体已被弃用,并将在其下一个主要版本(v2)中删除。现在,您还必须通过font属性传递字体系列。

printJS({
  printable: "print-element",
  type: "html",
  style: `@import url('https://fonts.googleapis.com/css?family=Annie+Use+Your+Telescope');`,
  font: 'Annie Use Your Telescope'
})

以下是上面例子的小提琴: https://jsfiddle.net/crabbly/Lt2nvagc/