3

My HTML file has some paragraphs where I am using an 8pt font-size. After converting the HTML to PDF, the paragraphs gain extra letter spacing and some letters are overlapped.

I tried all the suggestions from the following (like using dpi and xserver) but none are working.

http://code.google.com/p/wkhtmltopdf/issues/detail?id=72&q=letter

Nanne
  • 64,065
  • 16
  • 119
  • 163
Sharath B. Patel
  • 401
  • 1
  • 6
  • 15

4 Answers4

7

I realize that this question is a little bit old. But having received my fair share of frustration from this wkhtmltopdf letter-spacing issue, I want to drop a potential workaround:

'--dpi 96'

Add this option to the binary parameters, and you might be able to smile as I eventually did! viz:

wkhtmltopdf --option1 --option2 --dpi 96 "www.host.com/page.html" file.pdf
Ifedi Okonkwo
  • 3,406
  • 4
  • 33
  • 45
  • As the OP says: "After converting the HTML to PDF, the paragraphs gain extra letter spacing and some letters are overlapped." That was also my experience for any text where I had applied CSS `letter-spacing`, until I added the dpi option as above. Just a workaround! I honestly do not fully grasp the error - a bug, I guess. – Ifedi Okonkwo Jun 06 '14 at 09:24
  • Nice workaround - however extra space is still here. Ever found a perene solution ? – Mat Nov 18 '14 at 18:03
  • "Perene"? Guess you mean permanent as in "perennial"! Well, sadly nope. Actually, I haven't dwelt on this issue much lately. – Ifedi Okonkwo Nov 19 '14 at 09:41
  • 1
    This worked for me. I didn't realize it at first, because I've been having a separate issue where I'm not seeing certain styles show up. I ran the following tests: without dpi specified convert an html element that does not have letter-spacing style applied, and see that the letter-spacing is less in the pdf. Without dpi specified convert an element with letter-spacing: 1px; and see that letter spacing is more than 1px in the pdf (looks more like 5px). With dpi specified convert an element with letter-spacing 1px and notice that there is more spacing than with no letter-spacing specified. – Patrick Graham Mar 16 '15 at 14:25
  • This worked for me, too, on version 0.12.3 with a negative letter-spacing of -0.3mm. – hmundt Jun 15 '16 at 08:45
  • Thank you, it worked for me with dpi 96, and now the letter spacing is great! – Nicholas Jun 15 '16 at 13:56
1

In 2021 I fixed this by using 200 dpi.

FloPinguin
  • 351
  • 1
  • 5
  • 16
0

Guys if you want to to get your PDF View as it looks in your Web Page copy the following code in your config/initializer/pdfkit.rb(create this file in initializer folder)

PDFKit.configure do |config| 
config.wkhtmltopdf ='/usr/local/bin/wkhtmltopdf'
config.default_options = {
   :encoding=>"UTF-8",
   :page_size=>"Ledger",
   :zoom => '1.3',
   :disable_smart_shrinking=>false
}
end

Plese check this link for more ":page_size "attributes

wkhtmltopdf: What paper sizes are valid?

And discover new options by visiting this link

http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html

Hope This all will help you. Thanks

Community
  • 1
  • 1
Muhammad Ateq Ejaz
  • 1,845
  • 20
  • 22
0

Update wkhtmltopdf.

I found the best way to fix these letter spacing issues is to just ensure you're using the latest version of wkhtmltopdf (0.12.2.1 at the time of writing).

In Rails you can simply use the edge binary gem of this, like so:

gem 'wkhtmltopdf-binary-edge'

Give that a quick try first and see if your issues are fixed. Mine were.

Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245