Hi, I need to export data to a PDF file with proper CSS as displayed in HTML. Could you please tell me what is the best and proper way to do this.
Thanks, Nitin Mathur.
Hi, I need to export data to a PDF file with proper CSS as displayed in HTML. Could you please tell me what is the best and proper way to do this.
Thanks, Nitin Mathur.
There are lots of ways to do this, and deciding which one is right for your app takes a LOT more information than your post provides...
--Matt Jones
Try prawn gem. Its a good place to start so here http://prawn.majesticseacreature.com/
Hope it helps.
If you have a linux server, you can use wkhtmltopdf. I found it non-trivial to set up, though.
Nitin Mathur wrote in post #1047547:
Hi, I need to export data to a PDF file with proper CSS as displayed in HTML. Could you please tell me what is the best and proper way to do this.
Thanks, Nitin Mathur.
Go with prawn gem.
Hi, Thanks for your replies.
First I’ll put more details of my development environment and the requirements:
I have linux server (FC8). The project was started 4 years back with Ruby 1.8.6 and Rails 1.2.3. It’s very old now but I can’t upgrade to latest version as it has become a big project and upgrading might cause lots of issues.
Regarding web server I am using native Mogrel server.
I need to export the whole HTML page as it is to the PDF with all the CSS styles present in the page. I prefer the Prawn gem way but unfortunately it isn’t supported in the version of Rails used in my project.
I have tried “****wkhtmltopdf”. I am seeing the issue that the application gets stuck while running the command to generate PDF.
I have also tried using "htmldoc gem" which works well with static HTML content in rpdf file. iterating over array is not working in rpdf.
Let me know if it’s possible to use Prawn with Rails 1.2.3 somehow. or, how to resolve issue seen with “wkhtmltopdf” binary execution.
Thanks!
If you are running wkhtmltopdf in debug mode, you need to run a separate mongrel and point the wkhtmltopdf to that url, otherwise it tries to hit your mongrel instance, which is waiting for wkhtmltopdf to finish running.
Cheers Simon
Thanks Simon. Let me try this approach. But not looks a satisfactory solution to me running two servers of same application.
Hi, Thanks for your replies.
First I'll put more details of my development environment and the requirements:
I have linux server (FC8). The project was started 4 years back with Ruby 1.8.6 and Rails 1.2.3. It's very old now but I can't upgrade to latest version as it has become a big project and upgrading might cause lots of issues.
Regarding web server I am using native Mogrel server.
I need to export the whole HTML page as it is to the PDF with all the CSS styles present in the page. I prefer the Prawn gem way but unfortunately it isn't supported in the version of Rails used in my project.
Take a look at PrinceXML, as it is designed to take (X)HTML and convert it to PDF. It runs as a separate binary on your server, and it's extremely powerful. It costs serious money, but there is a free evaluation version you can try.
Walter
You only need to do that for development (when you are testing PDF export). Your production system should already be running multiple instances (otherwise only one person can view your site at a time) all on the same url.