Skip to content

Instantly share code, notes, and snippets.

@HydrangeaPurple
Created August 6, 2021 09:55
Show Gist options
  • Select an option

  • Save HydrangeaPurple/2da4024ddace3ee68c00c49136be83ab to your computer and use it in GitHub Desktop.

Select an option

Save HydrangeaPurple/2da4024ddace3ee68c00c49136be83ab to your computer and use it in GitHub Desktop.
java版本加载字体
/**
*
* 全局加载jvm黑体字体
*
* @author chengyq
*
*/
@Component
@Order(1)
public class FontLoaderRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
ClassPathResource classPathResource = new ClassPathResource("simhei.ttf");
InputStream inputStream = classPathResource.getInputStream();
Font font = Font.createFont(Font.TRUETYPE_FONT, inputStream);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(font);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment