and what about epub?
any gem preferences?
thanks for your excellent work.
Ryan, great job as usual. I was already planning to check out those gems during these days so the timing of this screencast is just perfect.
Awesome with a capital A, I have been waiting for a library like this for ages.
Ryan,
Great stuff. The episode came sooner than I expected.
Thanks.
- Jermaine
A great gem! I love that it can be used as middleware! Thanks so much for the screencasts!
hm, pdfkit seems quite nice. But in a simple test umlauts weren't displayed correctly with wkhtmltopdf =/
I don't have the time to figure this out for now.
How possible is it to have Rails automatically save a copy of this pdf on the server? I need a confirmation sheet for our folks in the office to use and I'd prefer to not have to do them one at a time if possible.
Though, perhaps the better way to look at this is to render one massive pdf of the index template with some special formatting and page breaks instead of 500 show template pdfs.
Curious to know if anybody has tried creating a table including images?
really really cool screencast and very nice thing this pdfkit :)
Prawn for clean structures
PDFKit for fancy looks ;)
Great screencast, once again you were providential:
Just when I was thinking I had to learn Prawn I opened my RSS reader and there was your fresh new tutorial!
Thanks!
"Curious to know if anybody has tried creating a table including images?"
it should work for *any* html, as it uses webkit (the renderer from chrome, safari etc.) to 'display' the html page internally, then draws this into a pdf, in the same way you can export a pdf directly from any program on os x by clicking the PDF button in the print dialog.
"How possible is it to have Rails automatically save a copy of this pdf on the server? I need a confirmation sheet for our folks in the office to use and I'd prefer to not have to do them one at a time if possible."
you could probably create a controller action which uses pdfkit or similar to save a pdf directly to an arbitrary filesystem path. look through its api for a method which returns a File or IO object, it likely uses one internally anyway.
actually if you only need to do it once/rarely a rake task would be better than mucking up your controllers and routing
Hi again Ryan,
Can't really make page-break-before work, it's always cutting my tables...
What version of wkhtmltopdf are you using?
Thanks for plug, Mr. Bates!
I will very soon be working on wicked_pdf with the intention of bringing it up to date on Rails 3, and Ruby 1.9.2. I might be looking at relying upon PDFKit, if I can do so without losing any of the flexibility of wicked_pdf. I think that will ultimately be better for both projects.
Found out that page-break-before only works if you have a really simple layout, with very few nestings.
Now I only wish "page-break-inside: avoid;" would work...
Got to love PDFs and this should be very powerful. Can't wait to deploy in my app. Just one thing though, sems very straightforward, I followed the steps, in a test 2.3.8 app with a simple scaffold.
Can't get any text to display on the PDF itself, a PDF renders from the show action /show/1.pdf : but it just contains the word "nil" rather than displaying the record as the html view does.
Sorry if I'm being dense, any ideas?
page-break-avoid does not yet work in wkhtmltopdf. it's because this would require heavy changes in webkits rendering ...
If page-breake-before does not work. Try doing "clear: both; page-break-before: always; display: block;" ...
The clearing should do the trick.
Anyone knows how to display the current page number and the total number of pages?
Same problem as Rupert Fisher... I obtain a 'nil' blank page every time :(
Thank you for a great cast.
pdfKiT works great for me but only on Rails 3
in Rails 2.3.8 if I do ".pdf" on url it returns empty pdf with "nil". Anybody had that problem ?
Creating from command line works without any problems.
Many thanks.
Works fine in irb console but in the real app I get the following error:
Processing PostsController#show to pdf (for 127.0.0.1 at 2010-06-30 22:44:01) [GET]
Parameters: {"id"=>"1"}
Post Load (0.4ms) SELECT * FROM "posts" WHERE ("posts"."id" = 1)
Completed in 13ms (View: 4, DB: 0) | 406 Not Acceptable [http://localhost/posts/1.pdf]
Anybody know who to get this to work?
Any help would be greatly appreciated J.
Good lord man, you need to do something about the spam problem.
Route all comments through Kismet or Defensio for a start?
Thanks for this. Awesome alternatives to the expensive princeXML.
I am having the same error that marek(comment 26).
Environment:
Rails 2.3.8 con bundle.
wkhtmltopdf in '/usr/local/bin'
And the error:
406 Not Acceptable [http://localhost/whatever.pdf] and no output.
Any ideas?
Thank you
Hi, Great screencast.
having the same problem that 26 and 66
Can anyone give a hand?
To solve the problem with Rails 2.3++ look at http://github.com/perenecabuto/PDFKit/commit/c61f8d683c2894c2cfecf08b43707c63514c4c9f it works for me.
Hello Ryan,
thank you for another great episode. You can actually obtain the url text using css:
http://gist.github.com/465259
Of course, it's better to put that into a print.css stylesheet. I am not sure if it works in IE6, BTW.
Hi Ryan,
I was desperately looking for a working example of PDFKIT.
This is great!!!!
Thanks a lot!!!!!
Great episode; I'll have to check pdfkit out.
One note: instead of #pdf_link, maybe you could have used .no_print. It seems likely that there will be other items you don't want to print - using an id tag for that one seems pretty heavy.
But that's a nit! Thank again.
Thank god for the creation of ryanb ! ;) you save my ass every time, bro.
For everyone getting only "nil" rendered, check your logs. Likely it will say it want's a genereic template such as show.erb.
The patch quoted above which is at http://github.com/perenecabuto/PDFKit/commit/c61f8d683c2894c2cfecf08b43707c63514c4c9f
might work but it's not yet in the master branch AFAICT.
Hi Fredrik,
to add page numbers, you can add some spans to the header HTML that will be replaced, see: http://madalgo.au.dk/~jakobt/wkhtmltopdf-0.10.0_beta4-doc.html#Headers%20And%20Footer%20Options. Setting the header is easier using wicked_pdf.
The article written by you very good, I like it very much. I will keep your new article.
Great Buddy how you know about this in very details, it is really very interesting and knowledgeable things.
I've been using Prawn, but find it too time consuming. I installed PDFKIT and can run my page if I type in the URL.pdf, but when using the link_to... :format => pdf, it still launches the Prawn formatted doc.
I've removed the pdf.prawn doc, the environment.rb requirement, as well as the vendor/plugin contents, but it still launches the prawn doc. WTF?
I tried uninstalling the Prawn gem, but phusion won't start my app at all.
So...where else are these prawn files hiding that won't let PDFKIT take over?
I've been using Prawn, but find it too time consuming. I installed PDFKIT and can run my page if I type in the URL.pdf, but when using the link_to... :format => pdf, it still launches the Prawn formatted doc.
I don’t know what to say except that I have enjoyed dsd
One thing I'd like to know - this is great but it bestows a PDF view on all the resources, could be good but overkill for what I'd like. How would I have more fine grain control over what gets the PDF treatment <- maybe with a link on certain pages saying "show pdf".
It is my pleasure to read this article,I look forward to reading more.
The article written by you very good, I like it very much. I will keep your new article.It is my pleasure to read this article,I look forward to reading more.
A great gem! I love that it can be used as middleware! Thanks so much for the screencasts!
@bingobob: I was also concerned that every page can be rendered as .pdf. I only have one page that makes sense. Instead of doing the middleware step, I think I can just call: `wkhtmltopdf --page-width 8.5in --page-height 11.0in http://my.domain.com/my/url output.pdf` from my controller in the one place it is needed.
Can I just say, this blog is what got me through the day today. Every time I read it, I just get more and more excited about whats next. Very refreshing blog and very refreshing ideas. I'm glad that I came across this when I did. I love what you've got to say and the way you say it.
If you don't want to use the middleware for rendering (this might be the case if you want add a custom filename to the send_data method), you can do something like this:
format.pdf {
html = render_to_string(:action => "show.html.erb")
kit = PDFKit.new(html)
kit.stylesheets << "#{Rails.root}/public/stylesheets/print.css"
send_data kit.to_pdf, :filename => "Your-custom-filename.pdf", :type => 'application/pdf'
}
How to cache the PDF using Rails page caching and PDFKit
1. Disable the PDFKit middleware so that your controller handles the generation of the PDF.
2. Register PDF as a mime-type in environment.rb:
Mime::Type.register "application/pdf", :pdf
3. In your controller, cache pages just like normal with caches_page :show
4. create a format.pdf call in your respond_to block and init a new PDFKit object, pass in the url to the current action and call to.pdf on it.
respond_to do |format|
format.html # show.html.erb
format.pdf { render :text => PDFKit.new( post_url(@post) ).to_pdf }
end
Now in your cache directory you'll create two cache files - one .html and one .pdf.
Great job! Thanks for the useful informations. This is a bog help for us.
That is an awfully astounding column you've posted.Thanks a lot for that a fantastically amazing post!
love converse all star,love yourself.High quality low price.It's fit for you.
The blog article very surprised to me! Your writing is good. In this I learned a lot! Thank you!
Some times, to a certain need, we have to convert PDF to image for enjoyment.
Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it. My readers have about the same interets
format.html # show.html.erb
format.pdf { render :text => PDFKit.new( post_url(@post) ).to_pdf }
end
Now in your cache directory you'll create two cache files - one .html and one .pdf.
Now in your cache directory you'll create two cache files - one .html and one .pdf.
Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it.
I was thinking I had to learn Prawn I opened my RSS reader and there was your fresh new tutorial!
Came across your blog when I was searching bing I have found the bit of info that
I found to be quite useful.
This is really a nice guide for Newbies like me. Thank you.






