Question

First of all i know this type of posts are already been made but i've tried almost all of them and i'm not been able to get the results so here i'm again posting the same kind of question.

Second of all i'm not having an asset pipeline issue here, so please forget about that.

Now let me explain what i'm doing. I'm using rails 3.1 and ruby 1.9.2, i installed wicked_pdf as a gem and installed wkhtmltopdf as mentioned in the wiki by purging the already installed wkhtml and downloading and extracting the new one to /usr/bin/wkhtmltopdf

I have an initializer that contains the following:

wicked_pdf.rb

WickedPdf.config = { :exe_path => '/usr/bin/wkhtmltopdf'}

In my view i have a link_to method as follows:

_filters.html.haml

= link_to 'show pdf', jobs_report_jobs_path(:format => :pdf), :method=>"post"

note if i remove the :format => :pdf option it works fine

in my controller i'm doing the following:

report_jobs_controller.rb

respond_to do |format|
      format.html
      format.js
      format.pdf{
        render :pdf=>"jobs",
        :template => 'jobs.html.erb',
        :layout=>"jobs.html"
      }
end

note that i have tried from format.pdf alone without any options. I tried "jobs.pdf.erb", with and without layout option, all sorts of other options i don't even remember. All i get is a 406 not acceptable in the end.

Please guide me coz i need to implement this feature asap.

Regards,

Was it helpful?

Solution 2

i had a before_filter in my application controller that was checking every request with the mentioned format for authentication and i was missing pdf format there, so as soon as i put the :pdf in the list of formats for each incoming request it worked fine.

OTHER TIPS

406 means the request isn't valid (in regards to what is acceptable to that controller action)

I've had trouble with :format => :pdf before. Try :format => 'pdf'

The barebones implementation should just be:

format.pdf {
  render :pdf => 'jobs'
}

Also, is the link_to really supposed to be :method => "post"?

I too had the same issue. I work on ubuntu. AFter I installed wkhtmltopdf, I am not getting this error any more. in terminal run the command below:

$sudo apt-get install wkhtmltopdf

I hope this helps :)

I don't how much about wicked-pdf, but I once used pdfkit and this is how I did the rendering part:

def pdf
  respond_to do |format|
      format.pdf { render :text => PDFKit.new( Pdf.find(params[:id]).content ).to_pdf }
    end
end

I hope the code is clear enough and self-explanatory. My view code is:

<p><%= link_to "Download PDF", pdf_pdf_path(@pdf, :format => "pdf") %></p>  
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top