# Performing a mail merge using rails and ? any ideas?

**URL:** <https://www.ruby-forum.com/t/performing-a-mail-merge-using-rails-and-any-ideas/130731>\
**Category:** Rails\
**Created:** [March 2, 2008, 8:20pm UTC](https://www.ruby-forum.com/t/performing-a-mail-merge-using-rails-and-any-ideas/130731 "2008-03-02T20:20:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![crenner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/278dde/32.png) [@crenner](https://www.ruby-forum.com/u/crenner)\
**Post date:** [March 2, 2008, 8:20pm UTC](https://www.ruby-forum.com/t/performing-a-mail-merge-using-rails-and-any-ideas/130731/1 "2008-03-02T20:20:43Z")

</div>

When the user clicks a link, i want to merge the current customers  
details into a word document (\*.doc) and return it to the user as a  
download.

Does anybody have any ideas on what the best way to do it is?

I’m racking my brains trying to think of the best way to do this.

My ideal scenario :

1. User searches for customer
2. User selects which type of document to open, e.g. Reminder Letter 3
3. Browser sends the user a doc file, with the customers details already  
in the address part, ready for editing/printing.

ANy ideas welcome

Thanks

Chris

---

<div class="post-metadata">

**Author:** ![crenner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/278dde/32.png) [@crenner](https://www.ruby-forum.com/u/crenner)\
**Post date:** [March 3, 2008, 1:58am UTC](https://www.ruby-forum.com/t/performing-a-mail-merge-using-rails-and-any-ideas/130731/2 "2008-03-03T01:58:13Z")

</div>

This probably doesn’t help much, but would a PDF document be  
acceptable instead of a Word document? I recall reading about a  
package that produces PDFs from within PHP scripts… here’s the ref  
from the book: [PHP Pdf creation - R&OS download | SourceForge.net](http://sourceforge.net/projects/pdf-php/). I have no  
idea if such a beast exists for RoR (having a grand total of about 5  
days of experience in the field myself), but I would be interested in  
learning if one did, as I would find it useful myself.

–wpd

On Sun, Mar 2, 2008 at 2:20 PM, Chris R.

---

<div class="post-metadata">

**Author:** ![crenner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/278dde/32.png) [@crenner](https://www.ruby-forum.com/u/crenner)\
**Post date:** [March 3, 2008, 4:26am UTC](https://www.ruby-forum.com/t/performing-a-mail-merge-using-rails-and-any-ideas/130731/3 "2008-03-03T04:26:01Z")

</div>

There’s PDF::Writer for Ruby.

[http://ruby-pdf.rubyforge.org/pdf-writer/](http://ruby-pdf.rubyforge.org/pdf-writer/)

On Mon, Mar 3, 2008 at 11:27 AM, Patrick D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > I’m racking my brains trying to think of the best way to do this.

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![crenner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/278dde/32.png) [@crenner](https://www.ruby-forum.com/u/crenner)\
**Post date:** [March 3, 2008, 4:38am UTC](https://www.ruby-forum.com/t/performing-a-mail-merge-using-rails-and-any-ideas/130731/4 "2008-03-03T04:38:58Z")

</div>

Chris - (

On 2-Mar-08, at 10:25 PM, Ryan B. (Radar) wrote:

> from the book: [PHP Pdf creation - R&OS download | SourceForge.net](http://sourceforge.net/projects/pdf-php/). I have no
> 
> > ## When the user clicks a link, i want to merge the current customers 2. User selects which type of document to open, e.g. Reminder
> > 
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > >

I missed the original post - so hopefully I’m answering the right  
question.

I’ve done this exact thing before -

1, create a word template setting bookmarks.

1. Use the ruby OLE (activex) library to control word, iterating over  
the bookmarks, placing data in the new word doc from the database.

2. Then save the file, and sendfile it back to the users browser.

That’s the rough outline - you should be able to google for code  
samples. If you get really stuck let me know - I’m really busy - but  
can likely help out.

cheers,  
Jodi
