This is a method inside my Resources.class:
public static Font loadFont(String fontFileName)
{
BaseFont base = null;
try
{
base = BaseFont.createFont(Resource.class.getResource(fontFileName + "_font.ttf").toString(), BaseFont.WINANSI, true);
}
catch (DocumentException | IOException e)
{
e.printStackTrace();
}
Font font = new Font(base, Font.BOLD, 15);
return font;
}
Structure of my program is:
src (folder)
core (package)
//all (but one) classes used for program
resources (package)
class Resources (used to load resources into the "core" classes)
wingding_font.ttf
This is the snippet of the code which isn't working:
p = new Phrase("some random text");
p.setFont(Resource.loadFont("wingding"));
pa = new Paragraph(p);
pa.setFont(Resource.loadFont("wingding"));
document.add(pa);
When I open the PDF, text is there, but some font, which I guess is the default font, is used.
Note1: I tried to setting font to only Phrase(p), and to only Paragraph(pa), but that didn't change output in any way.
Note2: The Resource.loadFont("wingding"); methods try/catch didn't "catch" any errors.