After After a lot of blood sweat and tears I managed to write a pretty simple rails app that allows the user to write letter templates via TinyMce, these are then saved and can be viewed as pdf documents.
I decided to restrict the options in the wysiwyg editor as much as possible as some of the options don't work exactly as expected, but that's nothing a little gsub-ing couldn't solve if needed.
There is a ruby gem that wraps HTMLDOC which you'll need: PDF::HTMLDoc
Once you've got that, register the mime type, then you can do something like:
@letter_template = LetterTemplate.find(params[:id])
respond_to do |format|
format.html
format.pdf { send_data render_to_pdf({:action => 'show.rpdf', :layout => 'pdf_report'}), :filename => @letter_template.name + ".pdf", :disposition => 'inline' }
end
In the application controller i've added the render_to_pdf method like:
def render_to_pdf(options =nil)
data = render_to_string(options)
pdf = PDF::HTMLDoc.new
pdf.set_option :bodycolor, :white
pdf.set_option :toc, false
pdf.set_option :portrait, true
pdf.set_option :links, false
pdf.set_option :webpage, true
pdf.set_option :left, '2cm'
pdf.set_option :right, '2cm'
pdf.set_option :footer, "../"
pdf.set_option :header, "..."
pdf.set_option :bottom, '2cm'
pdf.set_option :top, '2cm'
pdf << data
pdf.generate
end
You'll find more documentation on HTMLDOC site that Travis Beale Linked to. Hope this helps get you on your way and unless your documents are really complicated it should suffice. Let us know how you get on.