Hi, i'm trying to use document processing to convert HTML template to PDF, but fonts are missing from resulting file, maybe even from the imported html.
How can I find out if the fonts are already missing after importing HTML?
What is the best way to convert HTML to PDF keeping images, fonts, etc. using document processing?
This is one of my attempts to get it to work.
static void Main(string[] args)
{
string templateFileName = @"html template.htm";
string pdfPath = @"test html template to pdf.pdf";
FileStream templateAsStream = new FileStream(templateFileName, FileMode.Open, FileAccess.Read);
///////////
//telerik
///////////
try
{
// Register the font
byte[] fontDataR = File.ReadAllBytes("Raleway-VariableFont_wght.ttf");
System.Windows.Media.FontFamily fontFamilyR = new System.Windows.Media.FontFamily("Releway");
byte[] fontDataRL = File.ReadAllBytes("Raleway-Light.ttf");
System.Windows.Media.FontFamily fontFamilyRL = new System.Windows.Media.FontFamily("Releway Light");
//Telerik.Windows.Documents.Fixed.Model.Fonts.
FontsRepository.RegisterFont(fontFamilyR, System.Windows.FontStyles.Normal, System.Windows.FontWeights.Normal, fontDataR);
FontsRepository.RegisterFont(fontFamilyRL, System.Windows.FontStyles.Normal, System.Windows.FontWeights.Normal, fontDataRL);
byte[] fontDataRb = File.ReadAllBytes("Raleway-Bold.ttf");
System.Windows.Media.FontFamily fontFamilyRb = new System.Windows.Media.FontFamily("Releway");
//Telerik.Windows.Documents.Fixed.Model.Fonts.
FontsRepository.RegisterFont(fontFamilyR, System.Windows.FontStyles.Normal, System.Windows.FontWeights.Bold, fontDataRb);
//import AFTER setting fonts
//Telerik.Windows.Documents.Flow.FormatProviders.Html.
HtmlFormatProvider htmlProvider = new HtmlFormatProvider();
HtmlImportSettings importSettings = new HtmlImportSettings();
HtmlExportSettings exportSettings = new HtmlExportSettings();
var document = htmlProvider.Import(templateAsStream);
PdfFormatProvider pdfProvider = new PdfFormatProvider();
//Telerik.Windows.Documents.Extensibility.FontsProviderBase fontsProvider = new FontsProvider();
//Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.FontsProvider = fontsProvider;
PdfExportSettings pdfExportSettings = new PdfExportSettings();
pdfExportSettings.ShouldEmbedFonts = true;
pdfProvider.ExportSettings = pdfExportSettings;
FileStream stream = File.Create("fixed pdf.pdf");
var radFixedDocument = (new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider()).ExportToFixedDocument(document);
var fixedFormatProvider = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider();
fixedFormatProvider.Export(radFixedDocument, stream);
stream.Close();
//var resultBytes = pdfProvider.Export(document);
//File.WriteAllBytes(pdfPath, resultBytes);
}
catch(Exception e)
{
throw e;
}
I have also attached html file that is result of importing html and then export html
also I get this in pdf reader both if I use embed fonts option or not
https://www.telerik.com/forums/radflowdocument-to-pdf---arialnarrow-font-issues