8

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
4

3 に答える 3

9

これが役立つ場合、私は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

于 2012-04-26T16:19:37.467 に答える
6

HTMLファイルにメタタグが必要です。

...
<head>
  <meta name="pdfkit-orientation" content="Landscape"/>
</head>
...

次に、PDFは横向きになります。

于 2012-11-01T16:54:07.257 に答える
0

PDFKit は wkhtmltopdf のオプションを受け入れる必要があるため、これを使用してランドスケープ モードでレンダリングできるはずです。

def pdf_customer_shipments   
  @customer = Customer.find(params[:id])   
  @shipments = Shipment.where("customer_id = ? AND status = 'Open'", @customer.id
  render :layout => 'pdf', :orientation => 'Landscape' 
end 
于 2012-01-12T21:39:59.363 に答える