Search code examples
javascriptreactjspdfreact-pdf

React pdf-renderer does not display characters č, ć and đ


I'm using @react-pdf/renderer version "1.6.8". However, am unable to get the following characters: čćđ. Instead get empty spaces.

The characters are from the Croatian language and can be tested on their official page.

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

Might someone know what to setup or how to approach the problem. Haven't found anything on their official docs.

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


Solution

  • Try this

    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>
      )
    

    it works for me, for the Polish language