Does anyone have any suggestions for generating a word doc from a linux
rails application? We were using html and just naming it .doc, which
works well until you need to embed images into the document. MHT looks
promising but the only libraries aren’t free (not a deal breaker, but
free is better).
That’s a fabulous answer.
I wouldn’t be asking if I could convince my customers that a PDF would
do. They need to be able to edit the document after it is generated.
Does anyone have any suggestions for generating a word doc from a linux
rails application?
Yes: don’t do it. Word documents have no place on the Web – they don’t
reliably preserve formatting and they don’t play nice with Web browsers.
Generate a PDF file instead; prawn works well for this.
Yeah, docx would work, however the customer only has word 2003, which
doesn’t support that format.
the options I have found so far are:
mhtml - the only ruby lib is not free, and the format looks a bit
painful to build yourself
rtf - can’t see a ruby lib, but could build a servlet with java/itext
html - can’t embed the image, but can make it a link back to the server
(which is what we do with our old .net system), but is not ideal
I use OpenOffice here, but the customer has word, and have you ever
tried to convince a govt dept to change to open office? Not a quick/easy
job
Thanks
Simon
No I didn’t, and I probably snapped a bit more than I should have, but
you continually see people answering questions with negatives like that,
and it irks me.
That’s a fabulous answer.
I wouldn’t be asking if I could convince my customers that a PDF would do. They need to be able to edit the document after it is generated.
-1 for helpfulness
Totally off the wall here but .docx files are XML so why not generate
one in Word and then manipulate that from your app?
Another crazy idea is to use OpenOffice, I think they have a Java
interface that you might be able to hook into somehow.
I have not done either of these, just throwing out some ideas.
The only problem with HTML is that I can’t find a way to embed the image
(that works in Word), as opposed to having it link back to our server
(which isn’t the desired outcome).
No I didn’t, and I probably snapped a bit more than I should have, but
you continually see people answering questions with negatives like that,
and it irks me.
You also continually see people asking how to solve a problem in a way
they do not realize is suboptimal. Granted, that may not be the case
here, but that wasn’t obvious from your original question.
I would actually say that giving the client an HTML file might be the
way to go here. It’s not well known, but MS Word does a beautiful job
of importing HTML files (or did the last time I tried), including
parsing tags correctly. So your client should have no trouble
editing the file with Word, or with just about anything else, and you
won’t have to support a Web-unfriendly file format.
Cool, look forward to seeing the finished libraries.
In the mean time, I managed to get the embedded images working in an
html file.
Using the example here: http://www.htmlcodetutorial.com/help/ftopic5309.html
But for anyone following this, not the white space (ie empty lines) are
important.
There is an antique technique written up by Sam Neff at http://coldfusion.sys-con.com/node/41604 for ColdFusion. It works, and
you don’t need to run Word on your server. You don’t have to use
ColdFusion. In fact, you don’t need to run Windows. The source code is
still available at http://gemsres.com/story/41604/zip.html
Coldfusion is pretty easy to read, but if you get stuck, I’ll be glad
to interpret.
I won’t say it’s not a PITA, but it does work; I’ve used it. I think I
did a version of it in VBA out of MS Access. I even embedded the
graphics.
I didn’t think about that. I have html working fine now, but will keep
this in mind for when the customer (as is almost guaranteed) asks for a
more complex document.
The only problem with HTML is that I can’t find a way to embed the image (that works in Word), as opposed to having it link back to our server (which isn’t the desired outcome).
I am using this approach on a project with success. The only gotcha
is that you have to use the full URL of the image, instead of just the
path that Rails generates.
Here’s a helper method I used:
def image_url(img)
request.protocol + request.host_with_port + image_path(img)
end
Hope that helps
– Brandon
Idea Foundry: training takes a Holiday http://ideafoundry.info – Refer a friend and get $100
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.