I am converting HTML to PDF with itext version 8.0.4, but I get the following exception:
com.itextpdf.pdfua.exceptions.PDFUAConformanceException: Following font(s) are not embedded : Times-Roman
I get the above exception when I am trying to create the document object with PdfUADocument
class. There is no issue if the document object is created with PdfDocument
and if no conformance is set.
What is the cause of this exception?
The PDFUA specification requires you to embed all the fonts your PDF is using.
So to make this work in html2pdf you should configure the FontProvider to only use the fonts which are shipped as fontfiles.
Something like this should do the trick:
ConverterProperties converterProperties = new ConverterProperties();
FontProvider fontProvider = new DefaultFontProvider(false, true, false);
converterProperties.setFontProvider(fontProvider);
HtmlConverter.convertToPdf(new FileInputStream(sourceHtml), pdfDocument, converterProperties);
In the DefaultFontProvider
constructor the first false means: don't register the StandardPdfFonts these are fonts that every pdfProcesser should have available but they are not embedded so we need to turn that off. The second parameter is true as this will load fonts embedded in the library itself.
And the last false is to disable loading fonts that are available on your pc.
Of course if you are using custom fonts you can just add them to the font provider using the fontProvider.addFont()
method.
If this doesn't resolve it please provide more details.