Welcome Guest Search | Active Topics | Sign In | Register

HtmlToPdf - Embedding fonts+page header Options
Linus V.
Posted: Monday, August 22, 2016 10:11:06 AM
Rank: Newbie
Groups: Member

Joined: 4/19/2016
Posts: 7
Hey all,

I've managed to get embedding of a local font via @font-face working (data-uri base64 encoded since url(file:///x.ttf) doesn't seem to work.)

Now, my problem is:
With the following HTML:
Code: HTML/ASPX
<head>
	<style type="text/css">
		@font-face
		{
		font-family: Proxima;
		    src: url(data:font/truetype;charset=utf-8;base64,{{SNIPPEDOUT BASE64 ENCODED ttf-content}});
		}
		html, body {
                    font-family: Proxima;
		}
	</style>
</head>
<html>
	<body>
		<h1>TEst</h1>
	</body>
</html>


The rendered H1 has the correct font.

However when I add:
Code: C#
var options = new HtmlToPdfOptions();
            options.HeaderHtmlFormat = $"&lt;span style=\"font-family: Proxima;\"&gt;Text&lt;/span&gt;";


And use that, the header text does not get the correct font.



Am I missing something on how fonts get embedded, or do I have to do the page headers manually?
I will also have the same problem for page numbers since we need to add them after we have rendered it, since we don't know how many pages we will get...


Thankful for any hints I can get!
eo_support
Posted: Monday, August 22, 2016 10:37:20 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,082
Hi,

The header HTML is rendered in a different "document" by itself. So it does not share any CSS with the main document. If you want special font in your header/footer, you can include the CSS font-face in your HeaderHtmlFormat/FooterHtmlFormat.

Thanks!
Linus V.
Posted: Monday, August 22, 2016 10:39:27 AM
Rank: Newbie
Groups: Member

Joined: 4/19/2016
Posts: 7
eo_support wrote:
Hi,

The header HTML is rendered in a different "document" by itself. So it does not share any CSS with the main document. If you want special font in your header/footer, you can include the CSS font-face in your HeaderHtmlFormat/FooterHtmlFormat.

Thanks!



OK, I'll try that out.


Quick followup:
Is it intelligent enough to only include the font once?


Best regards,
Linus
eo_support
Posted: Monday, August 22, 2016 12:03:44 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,082
Hi,

Yes. That's what the browser's cache is for.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.