2

It work in my local machine. But in server got this error.

java.io.IOException: Problem reading font data.
at java.awt.Font.createFont0(Font.java:1000) ~[na:1.8.0_191]
at java.awt.Font.createFont(Font.java:877) ~[na:1.8.0_191]
at th.co.application.modules.qr.QrGenerateService.createQrImageWithText(QrGenerateService.java:141) ~[classes!/:0.0.577]
at th.co.application.modules.event.EventBackendController.create(EventBackendController.java:404) [classes!/:0.0.577]
...

My senior said, This problem about don't have permission to write temp. Because the server was AWS with auto scale. (Deploy with CI in Gitlab to Amazon ECS.)

DefaultResourceLoader loader = new DefaultResourceLoader();
InputStream fontFile = loader.getResource("classpath:static/fonts/MyCustomFont.ttf").getInputStream();

// Error in the line below.
Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile).deriveFont(80f);

Graphics2D g = image.createGraphics();
g.setFont(font);
...

How to solve it? Can I set custom temp dir for this case?

Thank you.

ThunderBirdsX3
  • 558
  • 1
  • 9
  • 25

0 Answers0