我想对一类文本进行样式设置,将我的文本设置为斜体。 我导入了Roboto字体,有很多样式,但我无法将其设置为斜体。
这是我的“css”(它不完全是CSS,因为它是react-renderer-pdf库中的样式)
Inspection: {
top: 15,
left: 55,
fontFamily: "Roboto",
fontSize: 7,
fontWeight: 'bold'
}
这个方法有效
Inspection: {
top: 15,
left: 55,
fontFamily: "Roboto",
fontStyle: "italic",
fontSize: 7,
fontWeight: 'bold'
}
这样就不行了
我分享了我的项目中字体结构的打印。
确保您已在
react-pdf
中正确注册了斜体字体
import { Font } from '@react-pdf/renderer';
Font.register({
family: 'Roboto',
fonts: [
{ src: 'path/to/Roboto-Regular.ttf' },
{ src: 'path/to/Roboto-Bold.ttf', fontWeight: 'bold' },
{ src: 'path/to/Roboto-Italic.ttf', fontStyle: 'italic' },
],
});
然后申请:
Inspection: {
top: 15,
left: 55,
fontFamily: "Roboto",
fontStyle: "italic",
fontSize: 7,
fontWeight: 'bold'
}