Pergunta

I'm using PDFKit in Rails that displays tables from my db. I want each table to have its own separate page. How can I achieve this?

html = "<p>HTML content here</p>"

kit = PDFKit.new(html, :page_size => 'Letter')
  output = kit.to_pdf

respond_to do |format|

format.pdf do
  send_data output, :filename => "trading_analysis.pdf",
                    :type => "application/pdf"
  end
end
Foi útil?

Solução

Okay not sure if this maybe what you are exactly looking for but it is certainly most worth considering. You could alternatively look at using wickedpdf and then wrapping a div around your content and the following in your CSS.

div.page {
  width: 180mm;
  height: 277mm;
  overflow: hidden;
  page-break-before: always;
}

EDIT: page-break-after: always; added a blank page at times, so we should use page-break-before: always;

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top