15 July 2011
Mark from Carriemail asked about using Google Webfonts</a> in the DocRaptor Rails Example (clone it from github).
Now that the link-fest is over, let’s talk about how to do that (it’s really easy).
In app/views/index.pdf.haml (original), I add the following to the <head> of the haml file used to make the PDFs:
%link{:href => "http://fonts.googleapis.com/css?family=Cantarell|Gravitas+One&v2", :rel => "stylesheet", :type => "text/css"}
%style{:type => "text/css"}
= "h1 { font-family: 'Gravitas One', cursive; font-weight: bold; }"
= "th { font-family: 'Cantarell', serif; font-size: 16px; }"
I also altered the table to use th and thead tags. The changes are on the google-web-fonts branch at github.
I added a couple of items to the sample app, and here’s what it looks like after the change (non-test document and font-size bumped).

Note: If you’re planning to use this in production, I highly suggest using Rails Layouts and external stylesheets to manage your common code and style settings.
Thanks for the question, Mark!
Links: