ruby-on-rails – Rails 3和PDFKit,如何将HTML文件转换为横向PDF?

我可以很好地将 HTML页面转换为PDF文档.问题是,我不知道如何将HTML文件转换为横向PDF.有没有办法在控制器中设置它?

从控制器……

def pdf_customer_shipments
  @customer = Customer.find(params[:id])
  @shipments = Shipment.where("customer_id = ? AND status = 'Open'",@customer.id)
  render :layout => 'pdf'
end

解决方法

如果这有帮助,我使用PDFKit并可以使用以下方式渲染PDF格式:
respond_to do |format|
  format.html
  format.pdf {
    html = render_to_string(:layout => false,:action => "my_page.html.haml")
    kit = PDFKit.new(html,:orientation => 'Landscape')
    kit.stylesheets << "#{Rails.root}/public/stylesheets/views/pdf.css"
    send_data(kit.to_pdf,:filename => "some_name.pdf",:type => 'application/pdf')
    return # to avoid double render call
  }
end

我从这里得到了方向部分:https://github.com/pdfkit/pdfkit/issues/12

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...