0

I am getting below error while working with pdfHtml add-on.

Actually the html content to pass into HTMLConverter.convertToPdf method is dynamic. This HTML content I get by reading outlook email from a folder using JavaMail API.

I am using iText7.1.9 and html2pdf2.1.6. I think the error is because of the compatibility issue between iText7 version and pdfHtml. I could not find any reference to check which pdfHtml version is compatible with which iText7 version. I found this link - https://github.com/itext/itext7/releases/tag/7.0.3 - but that does not list all the latest releases. Is there any way to know this?

[main] ERROR com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor - Unable to retrieve font:
 @font-face {
    font-family: "Cordia New";
    panose-1: 2 11 3 4 2 2 2 2 2 4;
}
[main] ERROR com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor - Unable to retrieve font:
 @font-face {
    font-family: "Cambria Math";
    panose-1: 2 4 5 3 5 4 6 3 2 4;
}
[main] ERROR com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor - Unable to retrieve font:
 @font-face {
    font-family: calibri;
    panose-1: 2 15 5 2 2 2 4 3 2 4;
}
[main] ERROR com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor - Unable to retrieve font:
 @font-face {
    font-family: "Cordia New";
    panose-1: 2 11 3 4 2 2 2 2 2 4;
}
[main] ERROR com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor - Unable to retrieve font:
 @font-face {
    font-family: "Cambria Math";
    panose-1: 2 4 5 3 5 4 6 3 2 4;
}
[main] ERROR com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor - Unable to retrieve font:
 @font-face {
    font-family: calibri;
    panose-1: 2 15 5 2 2 2 4 3 2 4;
}
[main] ERROR com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor - Unable to retrieve font:
 @font-face {
    font-family: "Cordia New";
    panose-1: 2 11 3 4 2 2 2 2 2 4;
}
[main] ERROR com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor - Unable to retrieve font:
 @font-face {
    font-family: "Cambria Math";
    panose-1: 2 4 5 3 5 4 6 3 2 4;
}
[main] ERROR com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor - Unable to retrieve font:
 @font-face {
    font-family: calibri;
    panose-1: 2 15 5 2 2 2 4 3 2 4;
}

I thought all the above fonts (mentioned in the error message) should be added to our application. So to test I added one of these fonts (Cordia New) but still I am getting the error. Is there any way to skip this error message so that it always use the default font?

Below is the code I used to add a font.

String font = "src/resources/fonts/cordia_0.ttf";
        
ConverterProperties cprops = new ConverterProperties();
FontProvider fontProvider = new DefaultFontProvider(true,false,false);
        
FontProgram fontProgram = FontProgramFactory.createFont(font);
fontProvider.addFont(fontProgram);
cprops.setFontProvider(fontProvider);

Below is a sample HTML generated from outlook (via JavaMail API).

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
    {font-family:"Cordia New";
    panose-1:2 11 3 4 2 2 2 2 2 4;}
@font-face
    {font-family:"Cambria Math";
    panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
    {font-family:Calibri;
    panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
    {margin:0cm;
    margin-bottom:.0001pt;
    font-size:11.0pt;
    font-family:"Calibri",sans-serif;
    mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
    {mso-style-priority:99;
    color:#0563C1;
    text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
    {mso-style-priority:99;
    color:#954F72;
    text-decoration:underline;}
span.EmailStyle17
    {mso-style-type:personal-compose;
    font-family:"Calibri",sans-serif;
    color:windowtext;}
.MsoChpDefault
    {mso-style-type:export-only;
    font-family:"Calibri",sans-serif;
    mso-fareast-language:EN-US;}
@page WordSection1
    {size:612.0pt 792.0pt;
    margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
    {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hi There,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Please review and let me know your feedback.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">XYZ<o:p></o:p></span></p>
</div>
</body>
</html>
user3742125
  • 617
  • 2
  • 9
  • 31
  • 1
    Font provider and `@font-face` rules are two different ways to add fonts. If you use `@font-face` rule then you need to provide `src` parameter (see https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face). If you add fonts with `FontProvider` then no need in `@font-face` declarations, just make sure that your HTML elements have right `font-family` set to them in their styles – Alexey Subach Jun 23 '20 at 22:10
  • Actually the html content to pass to HTMLConverter.convertToPdf method is dynamic. This HTML content I get by reading outlook email from a folder using JavaMail API. I have updated my question to include this. So ,as you suggested, I cannot provide src parameter since HTML content is generated dynamically in Outlook. – user3742125 Jun 24 '20 at 01:48
  • did you got the solution for it ? please post. it will be a great help – Amol Bais Jul 10 '20 at 06:42

0 Answers0