0

I have an app built in Rails 4 (Ruby 2) that currently opens the Browser print dialog box using Javascript when a button is clicked, like so:

<%= button 'Print Me', :onclick => 'window.print();return false;' %>

I noticed in the bottom left of this dialog box is a dropdown menu for 'PDF', which has a number of options including 'Open PDF in Preview', 'Save PDF as...' and a few others (Safari and Firefox both have this, so I assume it's industry standard). I'm particularly interested in the option 'Mail PDF' for use in my application, is it possible with some Javascript to access this functionality on button click in addition to the Print action it is already performing?

Ideal result would be that a button "Print and Email" is clicked and an email client opens with an attached printout of the current window in PDF format.

It seems to me this kind of thing should be possible using a combination of Javascript and/or HTML (especially mailto: like the question linked below), but I'm not familiar enough with Rails or Javascript to figure it out on my own.

mailto: example Link to open email client and attach file?

Thanks =)

1 Answer 1

1

Not possible, You can generate a PDF using DocRaptor, or you can use a ruby gem: https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&q=pdf

Alot of people like Prawn, i like flying saucer but it requires jRuby.

Pdfkit is a great option also as it uses Webkit which is the same engine as browsers like chrome.

https://github.com/pdfkit/pdfkit

Also after you've generated your PDF you can use a rails mailer and use the pdf as an attachment giving a similar email pdf functionality that you are looking for. Or you could save the file to public and launch a mail to that includes a link to the pdf you generated.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.