我在Django有一个项目,我想将一些文本渲染为pdf。它已经在工作,但是现在我需要更改字体。我在PC上安装了Gotham字体,并且我使用了所有文档,但现在我想用Gotham字体呈现pdf。

我下载了字体并将其放在我的templates文件夹中:



myproject/
     |-- myproject
     |-- templates/
          |-- admin/
          |-- font/
              |-- GothamBookItalic.ttf
              |-- GothamBookLight.ttf
              |-- GothamBookLIghtItalic.ttf
              |-- GothamBookMedium.ttf


这是我的html的CSS



@font-face {
                font-family: GothamMedium;
                src: url('/font/GothamMedium.ttf') format('truetype');
            }


但没有用,我也不知道该怎么办。

最佳答案

您将需要Gotham webfont。哪个应该是.woff文件。

您确实尝试使用.ttf TrueTypeFont。不适用于现代Web应用程序。

这是一个示例,看起来像这样:

@font-face {
    font-family: 'GothamMedium';
    src: url('fonts/GothamMedium-webfont.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}


也可能看起来像这样,以实现更广泛的浏览器兼容性:

@font-face {
  font-family: 'GothamMedium';
  src: url('fonts/GothamMedium-webfont.eot?') format('eot'),
  url('fonts/GothamMedium-webfont.woff') format('woff'),
  url('fonts/GothamMedium-webfont.ttf') format('truetype'),
  url('fonts/GothamMedium-webfont.svg#webfontdSscXrwb') format('svg');
  font-weight: normal;
  font-style: normal;
}


也许这就是您要寻找的:https://gist.github.com/mfd/f3d96ec7f0e8f034cc22ea73b3797b59

10-07 14:06
查看更多