-
Notifications
You must be signed in to change notification settings - Fork 400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using font-face #24
Comments
Can you try with other font format than .ttf, for example ,woff? Look at this issue |
Thanks. However that did not work for me. Am I putting the font file in the right place? |
Please prepare reproducible project and I could take a look. |
Ok here is a test project which resembles my project |
Replace your public async Task<IActionResult> Get()
{
await Task.CompletedTask;
string cssPath = @"file:///" + _hostingEnvironment.ContentRootPath + @"\wwwroot\fonts.css";
string html = "<!DOCTYPE html>" +
"<html lang = \"en\">" +
"<head>" +
"<meta charset = \"UTF-8\">" +
"<title> Check </title>" +
"<link href='" + cssPath + "' rel='stylesheet' type='text/css' media='screen'>" +
"</head>" +
"<body>" +
"<div style = \"text-align: center; margin-top:16px;\">" +
"<p style=\"font-family: 'MICR Encoding', sans-serif; font-size: 30px;\"> 235 384756 13425346 9877</p>" +
"</div>" +
"<div style = \"text-align: center; margin-top:16px;\">" +
"<p style=\"font-size: 30px;\"> This line doesn not have a font specified</p>" +
"</div>" +
"</body>" +
"</html>";
var pdf = new HtmlToPdfConverterService(_converter).Convert(html);
var path = Path.Combine(_hostingEnvironment.WebRootPath, "micr.pdf");
using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write))
{
fs.Write(pdf, 0, pdf.Length);
}
return Ok();
} As far I know wkhtmltopdf doesn't support relative paths for that reason I added In
Here is the result of the conversion. |
Thank you so much! It's working! |
Is this a cross platform solution @rivkawaxman i.e linux, mac? |
I tried the solution, using external css, but it's not working for me.
Is there anything I am missing? EDIT: |
Works for me |
I am trying to include a font from a ttf file.
I put the ttf file in the wwwroot folder of my project and i have this in my css in my html file:
@font-face {
font-family: 'MICR';
src: url("micrenc.ttf") format("truetype");
font-weight: normal;
font-style: normal;
}
and this on the line that needs the font:
style="font-family: 'MICR'; font-size: 30px;
The pdf file does that is created does even not include the text that is supposed to be in that font.
(when i render this file in my browser, i do see the text and in the specified font)
The text was updated successfully, but these errors were encountered: