ruby-on-rails – Rails 3和PDFKit,如何将HTML文件转换为横向PDF
发布时间:2020-12-16 21:59:26 所属栏目:百科 来源:网络整理
导读:我可以很好地将 HTML页面转换为PDF文档.问题是,我不知道如何将HTML文件转换为横向PDF.有没有办法在控制器中设置它? 从控制器…… def pdf_customer_shipments @customer = Customer.find(params[:id]) @shipments = Shipment.where("customer_id = ? AND st
我可以很好地将
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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |