I'm trying to email a .pdf in landscape format. I've been using the WickedPdf.new.pdf_from_string method to attempt to do this. Even though I specify landscape format, the emailed PDF is in portrait.
If someone could show me a way to accomplish this, I'd be most appreciative.
Mailer:
class ProjectMailer < ActionMailer::Base
def email_mindmap_process(project, user, unused_list_items_column1, unused_list_items_column2)
@project = project
@user = user
mail(:subject => "You've received a MindMap from #{@user.email}!", :to => @project.destination_email) do |format|
format.pdf do
attachments["#{@project.title}.pdf"] = WickedPdf.new.pdf_from_string(render_to_string(:pdf => "MindMap", :template => 'projects/show.pdf.html.erb', :orientation => 'Landscape', :locals => {:project => @project, :user => @user }))
end
end
end
end
Controller:
def email_mindmap_process
@project = Project.find(params[:id])
@user = current_user
begin
ProjectMailer.email_mindmap_process(@project, @user, @unused_list_items_column1, @unused_list_items_column2).deliver
flash[:notice] = "We have emailed your MindMap to #{@project.destination_email}"
rescue Net::SMTPAuthenticationError, Net::SMTPServerBusy, Net::SMTPSyntaxError, Net::SMTPFatalError, Net::SMTPUnknownError => e
flash[:error] = "There was a problem emailing #{@project.destination_email}. Please double-check the address"
end
end
I contacted the creator of the WickedPDF gem, Miles Sterrett, and he recommended the following, which worked perfectly!
attachments["#{@project.title}.pdf"] = WickedPdf.new.pdf_from_string(render_to_string(:pdf => "MindMap", :template => 'projects/show.pdf.html.erb', :locals => {:project => @project, :user => @user }), {:orientation => 'Landscape'})
Big thanks to Miles for responding promptly, and for building such a useful gem!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With