After I managed to write a rather simple application for rails after a lot of sweat and blood tears, which allows the user to write letter templates through TinyMce , they are then saved and can be considered as PDF documents.
I decided to limit the parameters as much as possible in the wysiwyg editor, since some of the parameters did not work exactly as expected, but something small gsub-ing could not be solved if necessary.
There is a ruby stone that wraps HTMLDOC that you will need: PDF :: HTMLDoc
Once you get this, 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 added the render_to_pdf method, for example:
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 will find additional documentation on the HTMLDOC website with which Travis Beale is associated. Hope this helps you along the way, and if your documents are really complex, that should be enough. Let us know how you are doing.
tsdbrown May 8 '09 at 2:43 pm 2009-05-08 14:43
source share