Question

I'm generating pdf with gem pdfkit (successfully) only issue that I have is that my pdf links are pure text (with color doh) but I cannot click on them

Generated pdf file: http://bit.ly/MZBdmL

the HTML

<h2>links</h2>
<p>
<a href="http://google.com" title="">google.com</a>
</p>
<p>
<a href="http://github.com">github</a>
</p>
<p>
<br>
</p>
<p>
<a href="http://google.sk" title="">http://google.com</a>
<br>
</p>

Am I missing some option in pdfkit or wkhtmltopdf ?

wkhtmltopdf version 0.9.9
pdfkit gem version  0.5.2

the way I'm generating pdf:

class DocumentController < ApplicationController

  def download
    @document = Document.last  #just example
    #...
    kit = PDFKit.new(@document.content.html_safe, :page_size => 'Letter')
    kit.stylesheets << "#{Rails.root}/app/assets/stylesheets/pdf.css"
    send_data kit.to_pdf, :filename => "#{@document.title}.pdf", :type => 'application/pdf'
  end
end

-----------------------------------------------------------------------------

Solution:

As @Nenotlep sugested in answer below, the solution was in reinstalling wkhtmltopdf. The version that I had before was from Ubuntu sources (lazy Synaptic instalation).

So I downloaded wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2 (i386 if you're not on 64bit platform) from official site http://code.google.com/p/wkhtmltopdf/downloads/list and extract it to

 ~/.rvm/gems/ruby-1.9.3-p194@my_project_gemset/bin 

so you'll get executable

 ~/.rvm/gems/ruby-1.9.3-p194@my_project_gemset/bin/wkhtmltopdf

restart server & done

note 1 The wkhtmltopdf manual suggest to place wkhtmltopdf static file anywhere my $PATH is pointing to. I was trying to put it in /usr/locale/bin however that doesn't work. As you see I use RVM. The file must be in specific gemset bin folder

note 2

on the download page are also files for wkhtmltoimage. Don't be dumb enough like me to install that and wonder why it's not working :)

Was it helpful?

Solution

Right off the bat I would recommend trying to install wkhtmltopdf by hand like it says in the Install part of the pdfkit homepage. That way you would get the latest version of wkhtmltopdf (0.11.0 rc2), which might fix many problems. (The changelog doesn't seem to have this issue listed though, so it might not fix whatever is the problem here.)

And as always with wkhtmltopdf issues one step that really helps in figuring out issues is doing the conversion by hand in the command line, that way you can make sure that the problem is with wkhtmltopdf and not the wrapper and also you get nicer feedback for what you are doing.

Sorry this isn't answering your question directly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top