Skip to content


Subversion checkout URL

You can clone with
Download ZIP


sobrinho edited this page · 24 revisions

Welcome to PDFKit!

PDFKit is a ruby gem that allows you to generate PDFs using only HTML/CSS. It requires wkhtmltopdf.

On this page are instructions for getting started with PDFKit. If you run into trouble, you can find information in the README and on the troubleshooting page.

Installing the gem

gem install pdfkit


See Installing WKHTMLTOPDF

Getting Started

# takes the HTML and any options for wkhtmltopdf
# run `wkhtmltopdf --extended-help` for a full list of options
kit =, :page_size => 'Letter')
kit.stylesheets << '/path/to/css/file'

# Get an inline PDF
pdf = kit.to_pdf

# Save the PDF to a file
file = kit.to_file('/path/to/save/pdf')

# can optionally accept a URL or a File.
# Stylesheets can not be added when source is provided as a URL of File.
kit ='')
kit ='/path/to/html'))

# Add any kind of option through meta tags'<html><head><meta name="pdfkit-page_size" content="Letter"')
Using cookies in scraping

If you want to pass a cookie to cookie to pdfkit to scrape a website, you can pass it in a hash:

kit =, cookie: {cookie_name, cookie_value})

Continue setting up:

Something went wrong with that request. Please try again.