Using @font-face with ABCPDF? Or other way of getting fonts into PDF?
Asked Answered
H

2

5

We have a large application successfully using ABCPDF.NET with HTML Styled text. We're accustomed to adding text using fonts not installed in Windows, but stored in files elsewhere in the filesystem -- we do this so each user can upload their own fonts and use them with the output. We use the AddFont call to embed the font in the Doc, then reference the font in a tag for HTML Styled text with the AddText call.

We're starting to look at using AddImageUrl / AddImageHTML to get more HTML power. Fonts are therefore a sticking point. It seems that both the MSHTML and Gecko engines will only see the same font list that Windows will.

I tried this code to see if @font-face will work with Gecko:

Sub Main
    dim pdf as new Doc
    with pdf.HtmlOptions
        .Engine = EngineType.Gecko
        .FontEmbed = true
        .FontSubstitute = false
        .FontProtection = false
    end with
    pdf.AddImageUrl("http://www.w3.org/2010/09/web-on-tv/slides/1009-tv-web-chaals/demos/webfonts.htm")
    pdf.Save("c:\temp\a.pdf")
End Sub

But it won't. Is there anything else I can do?

This is with ABCpdf.NET 8.1.0.7. Would upgrading to 9 or a later release of 8 help at all?

Haller answered 15/4, 2013 at 16:20 Comment(0)
H
8

NOTE:

As of ABCpdf 11, this works. Font files must either be at an accessible HTTP/HTTPS url (works with either AddImageHTML() or AddImageURL() or, if you wish to use a file:/// URL, you must write the HTML to a file and use AddImageURL(). Font files can be OpenType, TrueType, Type 1 or WOFF webfonts.

Sample code given in question works now, unchanged.


Previous answer:

WebSuperGoo responded:

ABCpdf does not currently support fonts added using @font-face.

So, as of the 9.0 release of ABCpdf, that's that.

Haller answered 16/4, 2013 at 17:0 Comment(3)
A clarification on this - ABCpdf WILL render fonts if they are installed on the machine rendering the pdf (no face-face css). However, if you do include font-face css it may actually break this behavior - causing it to not even embed installed fonts anymore. There I just saved you 3 days of hair pulling.Convolvulaceous
"Installed on the machine" is the situation I want to avoid ... I believe I covered that in my initial question. It's easy to get non-installed fonts useable by HTML Styled Text (doc.AddHtml). The goal was to get them available to the Gecko engine (doc.AddImageHtml).Haller
A note for those trying to use Glyphicons (will probably also work with bootstrap's Glyphicon-halflings): I was able to get glyphs working with doc.AddImageHtml by adding the following css only when building a pdf: .glyphicons { font-family:GLYPHICONS !important; } (the font will need to be installed on the server and the server rebooted)Cedeno
S
7

I work on ABCpdf and I can tell you that it is down as a feature request. The more people request it the sooner it will come. :-)

Sybilla answered 18/6, 2013 at 10:5 Comment(7)
I want it too please!Sorosis
I'd like it too, is there a UserVoice or something for ABCPDFTemplas
I really want this tooPoundal
@DanielPowell -- there's no UserVoice, but they monitor the #abcpdf tag here pretty closely.Haller
I want it too please!Anaphylaxis
Do you know whether this is any closer to being (or has been) implemented? ABCpdf 10 just came out, and it would be great if it supported @font-face (would probably make it worth upgrading for a lot of people).Cedeno
It seems ABCpdf 11 "supports web fonts, Font Awesome and similar dynamic font technologies." It seems that's only with the Chrome engine; don't know yet if that includes font-face. Time to experimentHaller

© 2022 - 2024 — McMap. All rights reserved.