Tomasz Borowski                  programmer at Selleo                  t.borowski@selleo.com        Generating beautiful P...
What is the problemGenerating PDF files may be a problem in web applications:    ●   tool is not based on HTML tags    ●  ...
SolutionUse wkhtmltopdf utility
Why this toolSeveral reasons to use wkhtmltopdf   ●   It is based on Webkit engine   ●   It interprets JavaScript, which m...
Simple Exampleswkhtmltopdf http://cnn.com cnn_page.pdfwkhtmltopdf http://en.wikipedia.org wiki_page.pdf
What If I need more    wkhtmltopdf allows you to generate pdf:●   from multiple resources●   with customized headers and f...
Ruby on Rails usageYou can use wkhtmltopdf through PDFKit gem!  ●   customize default PDF settings in initializer  ●   use...
Ruby on Rails usage: installationPDFKit:gem install pdfkitwkhtmltopdf:# download: http://code.google.com/p/wkhtmltopdf/dow...
Ruby on Rails: usage You can use wkhtmltopdf through PDFKit gem!    ●   customize default PDF settings in initializer    ●...
Ruby on Rails: configYou can customize default settings of PDFKit# config/initializers/pdfkit.rbPDFKit.configure do |confi...
Ruby on Rails: middlewareYou can create PDF view of any page of your application.It will be accessible by using .pdf forma...
Sources●   wkhtmltopdf homepage    http://code.google.com/p/wkhtmltopdf/●   wkhtmltopdf manual    http://madalgo.au.dk/~ja...
Upcoming SlideShare
Loading in...5
×

Generating beautiful PDF files

3,730

Published on

wkhtmltopdf and PDFKit in action

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,730
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
10
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Generating beautiful PDF files

  1. 1. Tomasz Borowski programmer at Selleo t.borowski@selleo.com Generating beautiful PDF files wkhtmltopdf and PDFKit in actionBielsko-Biała, 2011-01-10
  2. 2. What is the problemGenerating PDF files may be a problem in web applications: ● tool is not based on HTML tags ● tool does not interpret css definitions ● tool interpret only few css definitions ● output PDF document looks just awful ● ... ● tool is excellent but... it is not free :)
  3. 3. SolutionUse wkhtmltopdf utility
  4. 4. Why this toolSeveral reasons to use wkhtmltopdf ● It is based on Webkit engine ● It interprets JavaScript, which may be used to deliver some content ● It has number of useful options for PDF generation process ● It outputs nice looking PDFs! ● ... ● It is free (under GNU General Public License v3)
  5. 5. Simple Exampleswkhtmltopdf http://cnn.com cnn_page.pdfwkhtmltopdf http://en.wikipedia.org wiki_page.pdf
  6. 6. What If I need more wkhtmltopdf allows you to generate pdf:● from multiple resources● with customized headers and footers (ex. with page numbers)● with automatically generated table of contents● in grayscale, economic way ready to print● In custom size, zoom, orientation, with custom margins and... much more :)
  7. 7. Ruby on Rails usageYou can use wkhtmltopdf through PDFKit gem! ● customize default PDF settings in initializer ● use middleware to get PDF view of any page in application ● save PDF on server or render to browser
  8. 8. Ruby on Rails usage: installationPDFKit:gem install pdfkitwkhtmltopdf:# download: http://code.google.com/p/wkhtmltopdf/downloads/listxz -d wkhtmltopdf-xxx.tar.lzmatar -xf wkhtmltopdf-xxx.tarsudo mv wkhtmltopdf-xxx /usr/local/bin/wkhtmltopdf
  9. 9. Ruby on Rails: usage You can use wkhtmltopdf through PDFKit gem! ● customize default PDF settings in initializer ● use middleware to get PDF view of any page in application ● save PDF on server or render to browserkit = PDFKit.new(html, :page_size => Letter)pdf = kit.to_pdf # Get an inline PDFfile = kit.to_file(/path/to/pdf) # Save the PDF to a file
  10. 10. Ruby on Rails: configYou can customize default settings of PDFKit# config/initializers/pdfkit.rbPDFKit.configure do |config| config.wkhtmltopdf = /path/to/wkhtmltopdf config.default_options = { :page_size => Legal, :print_media_type => true }end
  11. 11. Ruby on Rails: middlewareYou can create PDF view of any page of your application.It will be accessible by using .pdf format, ex. /path/to/index.pdfAll pages:# in application.rbrequire pdfkitconfig.middleware.use PDFKit::MiddlewareCertain action example:# in environment.rbMime::Type.register "application/pdf", :pdf# in actionrespond_to do |format| format.html # index.html.erb format.pdf { render :text => PDFKit.new( post_url(@post) ).to_pdf }end
  12. 12. Sources● wkhtmltopdf homepage http://code.google.com/p/wkhtmltopdf/● wkhtmltopdf manual http://madalgo.au.dk/~jakobt/wkhtmltopdf-0.10.0_beta4-doc.html● PDFKit homepage https://github.com/jdpace/PDFKit
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×