Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emailing a WickedPDF in landscape orientation

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
like image 512
Quincy Larson Avatar asked Sep 16 '13 16:09

Quincy Larson


1 Answers

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!

like image 50
Quincy Larson Avatar answered Oct 06 '22 19:10

Quincy Larson