Your SlideShare is downloading. ×
Generating beautiful PDF files
Generating beautiful PDF files
Generating beautiful PDF files
Generating beautiful PDF files
Generating beautiful PDF files
Generating beautiful PDF files
Generating beautiful PDF files
Generating beautiful PDF files
Generating beautiful PDF files
Generating beautiful PDF files
Generating beautiful PDF files
Generating beautiful PDF files
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Generating beautiful PDF files

3,613

Published on

wkhtmltopdf and PDFKit in action

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,613
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
9
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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. 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. SolutionUse wkhtmltopdf utility
  • 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. Simple Exampleswkhtmltopdf http://cnn.com cnn_page.pdfwkhtmltopdf http://en.wikipedia.org wiki_page.pdf
  • 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. 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. 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. 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. 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. 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. 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

×