0

I've been long time investigating how to generate complex .pdf files (many images and 30 pages aprox). from a html web, of my rails application.

At the end I realized than the best option is wkhtmltopdf from command line.

  • using pdfKit gem don't work in production, but it works in development
  • using wkhtmltopdf from command line, works in development but neither in production.

I have read a lot of issues with wkhtmltopdf, so I abandon use wkhtmltopdf getting info from production web server. --> Instead I have created a new environment "genera_pdf" to run in production database, with development configuration (assets, cache..etc)

And now I need to run some proces than execute this:

1) RAILS_ENV=genera_pdf rails s

2) wkhtmltopdf localhost:3000 result.pdf

3) stops (CTRL+C) rails s

If this is achievable, Whats the best way to do this in Linux?

I'm absolutly missed...with rake tasks? or rails runner? or Cron-task?

Thanks a lot

Kris
  • 19,188
  • 9
  • 91
  • 111
Albert Català
  • 2,026
  • 2
  • 29
  • 35
  • From this http://wkhtmltopdf.org/ it doesn't look like you need served html, only html. Why not render html from your templates directly without going through a web server and invoke the library to run the render that way? – jjk Apr 05 '16 at 15:39
  • This means using pdfkit gem, and it is a solution, adding the `config.middleware.use PDFKit::Middleware` in application.rb and then in the controller `response.headers["PDFKit-save-pdf"] = "...file.pdf"` as I can't run it from production server, I prefer to make it simple, I would like to know if it is `possible to make a task or call `rails runner` calling itself, a task like "wkhtmltopdf "hppt://localhost:3000 result.pdf" beeing http the "rails runner" call – Albert Català Apr 05 '16 at 15:50
  • I would look at the answers here: http://stackoverflow.com/questions/4377849/how-to-generate-pdf-from-markdown-using-pure-ruby Among other things, it talks about using a markdown processor as a pre-processor to generate PDFs. Without knowing more, this seems like a reasonable approach for your problem, as it avoids the nastiness of running a separate web server just to (as i understand it) generate html to feed into a pdf gen tool. – jjk Apr 05 '16 at 20:05

0 Answers0