2

I'm attempting to convert html to pdf with a couple elements in Calibri Light. I've been able to get Calibri, Calibri Bold, and Calibri Italics to work, but light has been giving me no end of trouble.

*Edit If I run it all as calibri light it's all calibri light, if I run it all as calibri it's all calbiri. The fonts are being loaded properly, but the converter isn't switching fonts within the document

I've tried 'Calibri Light' as well as Calibri-Light without success.

I created two elements one in Calibri Light one in Calibri

<span style="font-size: 12pt; font-family: 'Calibri Light', sans-serif;">Calibri Light</span><br /></span> 
<span style="font-size: 12pt; font-family: 'Calibri', sans-serif;">Calibri<br /></span>

Preview

After Rendering with Itext I get this

Font gets converted

                    //Adding Calibri-Light and Calibri to the fonts
                FontProvider fontProvider = new DefaultFontProvider(false, false, false);

                FontProgram fontProgramCalibri = FontProgramFactory.CreateFont(Settings.DefaultBodyFont);
                FontProgram fontProgramCalibriBold = FontProgramFactory.CreateFont(Settings.DefaultBoldFont);
                FontProgram fontProgramCalibriLight = FontProgramFactory.CreateFont(Settings.DefaultHeadingFont);
                FontProgram fontProgramCalibriItalics = FontProgramFactory.CreateFont(Settings.DefaultItalicsFont);

                fontProvider.AddFont(fontProgramCalibri, PdfEncodings.WINANSI);
                fontProvider.AddFont(fontProgramCalibriBold, PdfEncodings.WINANSI);
                fontProvider.AddFont(fontProgramCalibriLight, PdfEncodings.WINANSI);
                fontProvider.AddFont(fontProgramCalibriItalics, PdfEncodings.WINANSI);

                properties.SetFontProvider(fontProvider);

                //Creating Body Text
                HtmlConverter.ConvertToPdf(documentInstance.Text, pdfDocument, properties);

                pdfDocument.Close();
                document.Close();

                return memoryStream.ToArray();

1 Answers1

0

I ended up adding font-weight:300 to the html tags and it works correctly now. It seems Itext was defaulting to Calibri when it couldn't find a match. I'm still not 100% on why it wouldn't pickup Calibri Light,