letter-spacing is too large with wkhtmltopdf

后端 未结 9 1092
情书的邮戳
情书的邮戳 2021-02-06 07:30

I\'m using wkhtmltopdf to download a webpage as pdf.

But the css property letter-spacing seems doesn\'t work

font-size:20px; letter-spacing:0px;
<         


        
相关标签:
9条回答
  • 2021-02-06 07:46

    in the CSS add the Following Code for Body

    body {
    font-kerning: normal;
    text-rendering: optimizeLegibility;
    }

    and the --dpi 200. This Worked for Me.

    0 讨论(0)
  • 2021-02-06 07:47

    I had the same problem, I set the dpi to 96 (in wkhtmltopdf options) and worked, not sure why though.

    0 讨论(0)
  • 2021-02-06 07:49

    Using wkhtmltopdf 0.12.4 or 0.12.5 on Windows you can use --dpi 300 on the wkhtmltopdf command line, to almost solve the issue. If you zoom a lot you may still notice some letters have negligible differences in spacing, but the letters no longer overlap. And with --dpi 600 makes it almost perfect. The rendered pdf file size was not increased in my scenarios.

    0 讨论(0)
  • I had the same issue and I have solved it by

    sudo wget http://pastebin.com/raw.php?i=AmfYN3er -O /etc/fonts/conf.d/10-wkhtmltopdf.conf
    
    http://www.jeremydaly.com/how-to-install-wkhtmltopdf-on-amazon-linux/
    
    0 讨论(0)
  • 2021-02-06 07:53

    I had the same issue. I had to add the flage --disable-smart-shrinking and then played with dpi by increasing and decreasing progressively.

        wkhtmltopdf --page-size A4 --print-media-type --lowquality --disable-smart-shrinking --encoding UTF-8 --no-outline --image-quality 100 --javascript-delay 3000 --orientation Portrait --dpi 65 --margin-top 0in --margin-right 0in --margin-bottom 0in --margin-left 0in "http://localhost:3000/wa/reports/"
    
    0 讨论(0)
  • 2021-02-06 07:54

    Issue every one face with letter spacing, perfect solution is here.

    import pdfkit
    #SnippetBucket.com code for pdfkit
    path_wkthmltopdf = r'/var/www/aukcnydom/wkhtmltox/bin/wkhtmltopdf'
    config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
    #more better and more accurate code for DPI set
    config.default_options = {
            'page_size': 'A4',
            'print_media_type': True,
            'dpi': 96
        }
    pdfkit.from_string(mark_safe(unicode(self.document)),settings.MEDIA_ROOT +"/"+ path, options=options, css=style,  configuration=config)
    

    Than in css. Add your letter-spacing.

    p{letter-spacing: 0.4mm !important; text-align: justify ; font-kerning: normal; text-rendering: optimize-speed;}
    /* SNIPPETBUCKET.COM, CSS CODE WITH LETTER SPACING */
    

    This way simply resolve your issue and work perfectly letter spacing.

    Note: I had given sample, you may apply applicable changes with your code.

    0 讨论(0)
提交回复
热议问题