Skip to content
react PDF실무 경험

How to fix broken Korean text in react PDF

1 min readWorkMoved from my Tistory blogRead the Korean original

jsx
import {
  Document,
  Font,
  Page,
  PDFViewer,
  StyleSheet,
  Text,
} from '@react-pdf/renderer';
import React from 'react';

Font.register({
  family: 'SpoqaHanSans',
  src:
    'https://cdn.jsdelivr.net/gh/spoqa/spoqa-han-sans@01ff0283e4f36e159ffbf744b36e16ef742da6d8/Subset/SpoqaHanSans/SpoqaHanSansLight.ttf',
});

const styles = StyleSheet.create({
  viewer: {
    flex: 1,
  },
  korean: {
    fontFamily: 'SpoqaHanSans',
  },
  english: {},
});

const PDFDocument = () => {
  return (
    <PDFViewer style={styles.viewer}>
      <Document>
        <Page>
          <Text style={styles.korean}>
            한국어한국어한국어아아아국국국어어어
          </Text>
          <Text>English</Text>
        </Page>
      </Document>
    </PDFViewer>
  );
};

I just applied the font through style, and it works fine.

  • #react PDF
  • #broken Korean text

More in Work