Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I render @font-face in PhantomJS screen capture?

The screen capture is great, but the custom @font-face fonts aren't being rendered. Is it possible to correct this?

like image 675
Sam Duvall Avatar asked Sep 22 '11 21:09

Sam Duvall


People also ask

Can PhantomJS capture a screenshot?

Since PhantomJS is using WebKit, a real layout and rendering engine, it can capture a web page as a screenshot. Because PhantomJS can render anything on the web page, it can be used to convert HTML content styled with CSS but also SVG, images and Canvas elements.

How do I use a font in @font-face?

In the @font-face rule you must first define a name for the font (e.g. myFirstFont), and then point to the font file. To use the font for an HTML element, refer to the name of the font (myFirstFont) through the font-family property:

Is there a way to rasterize in PhantomJS?

In the examplessubdirectory, there is a script rasterize.jswhich demonstrates a more complete rendering feature of PhantomJS. An example to produce the rendering of the famous Tiger (from SVG):

What file formats does PhantomJS support?

Beside PNG format, PhantomJS supports JPEG, GIF, and PDF. In the examplessubdirectory, there is a script rasterize.jswhich demonstrates a more complete rendering feature of PhantomJS. An example to produce the rendering of the famous Tiger (from SVG):


2 Answers

After doing some research for a bit I found this

http://code.google.com/p/phantomjs/issues/detail?id=247

Looks like SVG works the best.

One problem I ran into while testing a screenshot again after using an SVG version of the font was WebKit caching the old page and still showing the broken fonts. Make sure your server explicitly tells it to not use a cached version, or clean WebKits cache.

like image 160
Brad Avatar answered Sep 22 '22 12:09

Brad


I've build PhantomJS with Webfonts support for OSX and Linux - You can use the binaries directly -

Download From: http://arunoda.me/blog/phantomjs-webfonts-build.html

like image 26
Arunoda Susiripala Avatar answered Sep 18 '22 12:09

Arunoda Susiripala