Wicked_PDF working in Rails 3.1

I recently updated one of my apps to Rails 3.1 and found that my PDF generating tests were failing because they were unable to find the CSS or images to use in the PDF.

So I started playing around, and here is what I got:

In your app, add a new initializer (or edit your existing wicked_pdf.rb initializer) and put the following:

As you can see in the code, I also replaced the background urls with correct references, this is assuming that you’re keeping your CSS images in the same location as your normal images (which I don’t see a reason why not but of course you can always tweak the script)

Possible Issues

Pow.cx

I had one issue with my generated PDF using pow.cx, my CPU would jump to 100% (on the pow process) and the page would timeout. After upgrading to the latest version of pow (0.3.2) using this command:

I was able to see my PDFs without an issue.

Additional Sources:

http://blog.phusion.nl/2011/08/14/rendering-rails-3-1-assets-to-string/
https://github.com/mileszs/wicked_pdf/issues/48

Small update: (14/02/2012)

Small change to the above code to fix issue that prevented CSS from being rendered correctly.

12 Comments

Comments are now closed.

%d bloggers like this: