首页 > 解决方案 > React pdf-renderer 不显示字符 č、ć 和 đ

问题描述

我正在使用@react-pdf/renderer版本“1.6.8”。但是,我无法获得以下字符:čćđ。取而代之的是空白。

这些字符来自克罗地亚语,可以在其官方页面上进行测试。

https://react-pdf.org/repl?example=page-wrap

可能有人知道要设置什么或如何解决问题。在他们的官方文档上没有找到任何东西。

Github 问题:https ://github.com/diegomura/react-pdf/issues/780

标签: javascriptreactjspdfreact-pdf

解决方案


尝试这个

import { Page, Font, Text } from '@react-pdf/renderer';

// Register Font
Font.register({
  family: "Roboto",
  src:
    "https://cdnjs.cloudflare.com/ajax/libs/ink/3.1.10/fonts/Roboto/roboto-light-webfont.ttf"
});

// Create style with font-family
const styles = StyleSheet.create({
  page: {
    fontFamily: "Roboto"
  },
});

const MyDocument = () => (

    <Document > 
      <Page size="A4" style={styles.page} > <!--Add Font style to the page-->
          <Text >Some text čćđ</Text>
      </Page>
    </Document>
  )

它适用于我,适用于波兰语


推荐阅读