DocRaptor

DocRaptor Does Google Web Fonts

Google Web Fonts are an easy way to add some panache to a website. With DocRaptor’s javascript and font-face support, they’re an easy way to add some style to a PDF.

Google’s Getting Started page has a a very simple example (reproduced below) that can be used to generate a simple PDF.

<html>
  <head>
    <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Tangerine">
    <style>
      body { font-family: 'Tangerine', serif; font-size: 48px; }
    </style>
  </head>
  <body>
   <h1>Making the Web Beautiful!</h1>
  </body>
</html>

If you’re using the Ruby Example from the DocRaptor Examples repo, you could change the PDF block to look like this (assuming you had saved the above html to a file named font-sample.html in the directory with straight_ruby_example.rb):

File.open("google-fonts-ftw.pdf", "w+") do |f|
  f.write DocRaptor.create(:document_content => File.read("font-sample.html"),
                           :name             => "google-fonts-ftw.pdf",
                           :document_type    => "pdf",
                           :test             => true)
end

After running the file through ruby, you should end up with a PDF named google-fonts-ftw.pdf that looks like this (caveat: I bumped up the font size, centered the text, and turned off test mode for this picture):
PDF generated image

And that’s it. Beautiful fonts in your PDFs with ease!