MattiasB
MattiasB

Reputation: 135

HTML to PDF Rails

I've tried PDFKit and wicked_pdf.

PDFKit almost got me where I wanted but it didn't have support for a css rule so that I could get the footer fixed in the bottom:

position: fixed;
bottom: 0;

Any workarounds to fix this?

Googling the subject doesn't give much except others like prawn and the likes with no html support.

For those who wonder. wkhtmltopdf is installed and works thus PDFKit works.

respond_to do |format|
  format.html {render :layout => nil}
  format.pdf do
    render :pdf => "file_name.pdf",

    :save_to_file => Rails.root.join('public/uploadedfiles', "filename")  
  end
end 

Upvotes: 3

Views: 2312

Answers (4)

Gareth
Gareth

Reputation: 138200

In CSS3 you could use an @page rule to include footers in this way:

@page {
  @bottom-center {
    content: "foo";
  }
}

This is supported in a lot of paid PDF solutions, e.g. PDFReactor and I think Prince.

However Webkit (which wkhtmltopdf is based on) doesn't support the CSS3 paged media rules so you need a fallback.

The Wicked PDF documentation lists a :footer option which you can use to pass in chunks of HTML to render in particular pages. This looks like the best option for you.

Upvotes: 2

illbzo1
illbzo1

Reputation: 470

I'd recommend looking into DocRaptor. It's got better CSS support than comparable programs, from my experience.

DocRaptor

Here's a link to the code for using DocRaptor with Rails:

DocRaptor Rails example

Upvotes: 0

Kristian Hildebrandt
Kristian Hildebrandt

Reputation: 1528

I am really not sure why you would want an element to be fixed in a pdf document, is that really what you want? Besides, both gems make use of wkhtmltopdf, which is an utility that makes use of webkit to render its html and ultimately convert it to pdf. Once it looks great on webkit, it should look great as pdf. But I dont think pdf supports elements to "fixed" as in CSS.

Upvotes: 0

Sauco82
Sauco82

Reputation: 3

I haven't tried PDFKit nor wicked_pdf so I'm just wondering. But maybe this could do the trick. Have you tried using Sticky Footer hack instead?

http://ryanfait.com/sticky-footer/

Upvotes: 0

Related Questions