I have a Rails app, in which I need to render one of the views as a downloadable PDF. The view itself is composed of many partials, which in turn are composed of more partials and so on. This is the top-level view:
<meta charset="utf-8" />
<%= javascript_include_tag "jquery-ui.min", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "report", media: "all", "data-turbolinks-track" => true %>
<%= stylesheet_link_tag "report_style", media: "all", "data-turbolinks-track" => true %>
<div class="report">
<%= render partial: "details", locals: { examinee: @examinee, te: @test_event } %>
<div class="page-break"></div>
<%= render partial: "grades", locals: { scores: @test_event.scores, tasks: Task.tasks_for_report(@test_event.language) } %>
<div class="page-break"></div>
<%= render partial: "ld", locals: { test_event: @test_event } %>
<%= render partial: "review", locals: { test_event: @test_event } %>
<div class="page-break"></div>
<%= render partial: "appendix" %>
</div>
Due to the complexity of the rendered view, I prefer generating a PDF from html over writing everything twice, once as .html.erb and again as pdf.erb.
I have tried both pdfkit and wickedpdf, but in both cases I have failed:
pdfkit gets my Thin server hanged, no matter what I tried - None of the solutions suggested here, here and here had any impact, things still suck.
wicked_pdf has actually managed to generate a PDF, but then again it ignored all of my css and js code, even when called with wicked_pdf_javascript_include_tag
and its corresponding css twin. This can't go as I need my page breaks and all of the content created by the various js scripts (for example, some plots which are made by chartist
).
Any Ideas?