Search code examples
rubyruby-on-rails-4pdfwkhtmltopdfwicked-pdf

PDF generation error with wkhtmltopdf


I'm having a strange issue when trying to copy text from a generated PDF. Following are the steps,

  • Generate the PDF using wicked_pdf gem
  • PDF generates correctly
  • When I do a select all on the PDF, the places it has letters fi, or ffi is not selecting
  • happens only in the server (linux), works fine in local (mac)

I'm using

  • wicked_pdf gem
  • wkhtmltopdf ver 0.12
  • Fonts 'Noto Sans SC', 'Noto Sans'
  • ruby 2.2.3
  • rails 4.2.5.2

Below is what is happening when I do a select all.

enter image description here


Solution

  • The reason might be due to having text-rendering set to optimizeLegibility in your css file. Remove this line:

    text-rendering: optimizeLegibility;

    and you should be gold :)

    Reference from Mozilla:

    "One very visible effect is optimizeLegibility, which enables ligatures (ff, fi, fl etc.) in text smaller than 20px for some fonts (for example, Microsoft's Calibri, Candara, Constantia and Corbel or the DejaVu font family)."

    Note that I had the same problem with the Noto font and optimizeLegibility definitely affects it.