Mail merges in ruby ​​on rails, but in large quantities

I am trying to implement merge sorting for printed documents in Ruby on Rails 3.2. I have about 8000 recipients and templates in Microsoft Word. The template includes images (photographs) and contains about 10-20 pages.

The actual situation is that I rewrote the original template in Textile (redcloth), and the images are pasted from the Internet (http-address). I did all the personalization, etc. Therefore, I am creating an HTML file and have to split it into many small files of 1000 pages. In total I need to print about 8000 x 20 pages = 160,000 pages.

Does anyone know how to print it in PDF from HTML? Or how to insert commands to change the paper tray (for the first and last page) or for binding after every 20 pages, etc.?

Thanks for any idea :-)

+5
source share
1 answer

Here is one idea: in your rails application, configure it to return one html per user. In addition, you have a nice / users / index method that returns a list of users in a convenient, possibly json format.

Now you need a local script written in ruby, bash, anything convenient:

  • select a list of users from this / users / method, maybe save it to a file
  • loop over the list of users (from the file, so they are not all in memory), and get the HTML email address
  • generate PDF from each loaded HTML, either inside a loop, or cycle through files in the directory in which you saved the HTML. Use wkhtmltopdf or similar.
  • pdf , , pdf .

, , ​​ resque, . pdf , , . , script .

0

All Articles