3
votes

There any way to use the gem 'prawn' with gem 'pdfkit' for to generate PDF starting from HTML.

With Prawn I'll make the document header and footer and the main or body for the pdf come from HTML tags with CKEditor and for this i'm using Pdfkit because Prawn is not, and will never be, is an HTML to PDF generator, have basic support for inline styling but it is limited to a very small subset of functionality and is not suitable for rendering rich HTML documents.

I would like to know if i can mix those gem, or, any idea or advice will be helpful,

Thank you in advance

1

1 Answers

2
votes

Well I could solved it using gem 'wicked_pdf' and gem 'wkhtmltopdf-binary', so with wicked_pdf have options that help you to make header and footer for you pdf and convert html to pdf.

Example code for header and footer on the controller - for more options link

class ThingsController < ApplicationController
  def show
    respond_to do |format|
      format.html
      format.pdf do
        render pdf: 'file_name',
           margin:  {   top:               SIZE,                     # default 10 (mm)
                        bottom:            SIZE,
           header:  {   html: {            template: 'users/header.pdf.erb',  # use :template OR :url
                                           layout:   'pdf_plain.html',        # optional, use 'pdf_plain.html' for a pdf_plain.html.erb file, defaults to main layout
                                           url:      'www.example.com',
                                           locals:   { foo: @bar }},
           footer:  {   html: {   template:'shared/footer.pdf.erb', # use :template OR :url
                                  url:     'www.example.com',
                                  locals:  { foo: @bar }},
      end
    end
  end
end