React-pdfで日本語を対応させたい
使用ライブラリ
react-pdf
indexjs
1Font.register(`${__dirname}fonts/Nasu-Regular.ttf`, { 2 family: "Nasu-Regular" 3});
Appjs
1 const styles = StyleSheet.create({ 2 text: { 3 fontFamily: "Nasu-Regular", 4 } 5 }); 6const MyDoc = () => ( 7 <Document> 8 <Page> 9 <Text style={styles.text} >日本語</Text> 10 </Page> 11 </Document> 12) 13<PDFDownloadLink document={<MyDoc />} fileName="somename.pdf"> 14 {({ blob, url, loading, error }) => (loading ? 'Loading document...' : 'Download now!')} 15</PDFDownloadLink>
フォントファイルをsrc/fontsに配置しFont.registerで呼び出しても
Unhandled Rejection (Error): Unknown font format
とエラーが出ます。
どうしたらフォントを適用できるでしょうか?
あなたの回答
tips
プレビュー