[Public] Adding new fonts using CSS
IronPDF automatically add and embed the fonts if the font file is included in CSS.
In this example, we can specify the font styling using custom CSS without the need of explicitly adding and embedding the font using APIs.
In this example, we can specify the font styling using custom CSS without the need of explicitly adding and embedding the font using APIs.
Below is the sample c# code and custom.css.
ChromePdfRenderer renderer = new ChromePdfRenderer();
Parameters.Add("persons", persons);
renderer.RenderingOptions.CustomCssUrl = $"wwwroot/css/custom.css";
PdfDocument pdf = renderer.RenderRazorComponentToPdf<Person>(Parameters);
File.WriteAllBytes("razorComponentToPdf.pdf", pdf.BinaryData);
custom.css :
@font-face {
font-family: 'DancingScript';
src: url('../fonts/DancingScript-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
body {
font-family: 'DancingScript', Arial, sans-serif;
}
This is file structure of wwwroot.
And this is the output.