Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fonts] Font family Times New Roman is not display, not work #2714

Open
tnmhoang opened this issue Apr 12, 2024 · 0 comments
Open

[Fonts] Font family Times New Roman is not display, not work #2714

tnmhoang opened this issue Apr 12, 2024 · 0 comments

Comments

@tnmhoang
Copy link

Screenshot 2024-04-12 at 08 53 40
import { Document, Font, PDFViewer, Page, StyleSheet, Text, View } from "@react-pdf/renderer"

import Normal from "./Times_New_Roman.ttf";
import { useCallback, useEffect, useState } from "react";

const PDF = () => {
Font.clear();
Font.reset();
Font.register({
family: 'Times-New-Roman',
src: Normal
})

console.log('font register should have happened', Normal);
console.log('registered getRegisteredFontFamilies', Font.getRegisteredFontFamilies());
console.log('registered getRegisteredFonts', Font.getRegisteredFonts())

const [isFontLoaded, setIsFontLoaded] = useState(false);

const loadFonts = useCallback(async () => {
await Promise.all([
Font.load({ fontFamily: 'Times-New-Roman' }),
]);
setIsFontLoaded(true);
console.log(Font.getRegisteredFontFamilies());
console.log('fonts loaded');
}, []);

useEffect(() => {
loadFonts();
}, [loadFonts]);

if (!isFontLoaded) {
// tslint:disable-next-line:no-console
console.log('isFontLoaded is FALSE');
return (
<></>
);
}
return (



        <Text style={{ fontFamily: 'Times-New-Roman' }}>Trịnh Ngọc Minh Hoàng</Text>
      </View>
      <View style={styles.section}>
        <Text style={{ fontFamily: 'Times-New-Roman' }}>Section #2</Text>
      </View>
    </Page>
  </Document>
</PDFViewer>

)
}

export default PDF;

const styles = StyleSheet.create({
page: {
flexDirection: 'row',
backgroundColor: '#E4E4E4'
},
section: {
margin: 10,
padding: 10,
flexGrow: 1
},
txt: {
fontFamily: 'Times-New-Roman'
}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant