0
votes

I used addDirectory() method to add two Cardo fonts at once:

public static final String FONTS = "src/main/resources/fonts/";
public void createPdf(String src, String fonts, String dest) throws IOException {
    ConverterProperties properties = new ConverterProperties();
    FontProvider fontProvider = new DefaultFontProvider();
    fontProvider.addDirectory(fonts);
    properties.setFontProvider(fontProvider);
    HtmlConverter.convertToPdf(new File(src), new File(dest), properties);
}

unfortunately Times font is used instead of Cardo or Cardo-Bold. I have also tried with other Arial fonts but it doesn't work also

I'm using iText 7.1.6 and pdfHTML 2.1.3

1

1 Answers

1
votes

The font that is eventually used is selected by font selection mechanism and depends on a number of factors. If you did not specify your font family name to Cardo in any way explicitly in the HTML then it is expected that Times is used by default.

If you want only the fonts you added to FontProvider to be used then you should use another DefaultFontProvider's constructor because the default one adds standard PDF fonts and several fonts that are shipped with pdfHTML. Using another constructor allows you to switch off adding those fonts in the background:

// Passing false three times means not loading standard PDF fonts, fonts shipped with pdfHTML and system fonts
FontProvider fontProvider = new DefaultFontProvider(false, false, false);
fontProvider.addDirectory(fonts);
properties.setFontProvider(fontProvider);