To add an additional fonts directory the you can use the next code snippet:
FontRepository.addLocalFontPath("fonts/DirOne");
FontRepository.addLocalFontPath("fonts/DirTwo");
If you want to overwrite all existing fonts and use only fonts from custom ‘dirs’ you can use the next code snippet:
List<String> newFontPathsList = new ArrayList<>();
newFontPathsList.add("fonts/DirOne");
newFontPathsList.add("fonts/DirTwo");
FontRepository.setLocalFontPaths(newFontPathsList);
One of the reasons why you receive a FontNotFoundException the font name does not equal the file name. Please check the font name:
Font font = FontRepository.openFont(fontDir + "Arial.ttf");
String fontName = font.getFontName();
System.out.println("Arial font name: "+fontName);
Font arial = FontRepository.findFont(fontName);
System.out.println("Arial font name: "+arial.getFontName());
Also, the you can explicitly add a font to the Aspose font repository:
Font font = FontRepository.openFont(fontDir + "Arial.ttf");
FontRepository.addSystemFont(font);
Font arial = FontRepository.findFont(font.getFontName());
System.out.println("Arial font name: "+arial.getFontName());
And finally, the you can change the font of the signature appearance:
PKCS7 signature = new PKCS7(pfxPath, "password");
SignatureCustomAppearance signatureCustomAppearance = new SignatureCustomAppearance();
signatureCustomAppearance.setFontSize(6);
signatureCustomAppearance.setFontFamilyName("Times New Roman");
signatureCustomAppearance.setDigitalSignedLabel("");
signature.setCustomAppearance(signatureCustomAppearance);
Times New Roman font or another font also must be accessible with the following:
Font font = FontRepository.openFont("Times New Roman");