Git Product home page Git Product logo

Comments (8)

dburry avatar dburry commented on July 27, 2024

How does your HTML code start out? mine starts out like:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />

and it works fine for me with Chinese in it... Also using 1.8.7 (non-EE) If you were missing the content-type...charset=utf-8 meta tag, I'd imagine it behaving like you describe (since this is how Safari behaves without it too).

from pdfkit.

jystewart avatar jystewart commented on July 27, 2024

Hmmm... thanks. Adding the meta tag seems to have resolved the problem. I'd not checked for that as the HTTP headers were already returning "text/html; charset=utf-8", but maybe the way pdfkit passes the data through doesn't preserve that? Seems worth a mention in the docs?

from pdfkit.

dburry avatar dburry commented on July 27, 2024

The underlying implementation is the wkhtmltopdf command line tool. For those who are generating or loading it internally, instead of pulling it from a remote source, there are no HTTP headers to confuse anyone on this point anyway. It could be possible I suppose to pass wkhtmltopdf remote HTTP headers when it's being pulled from an external HTTP source...

from pdfkit.

jystewart avatar jystewart commented on July 27, 2024

Right, I understand that now, though it is initially confusing that when I made the request using the command line tool directly it handled the utf8 content just fine (which turns out to be because my command line usage was causing wkhtmltopdf to work over http, whereas pdfkit hands it a string)

That's all fine, and makes sense. At this point I'm simply suggesting that it would be sensible to add a note about this to the docs as for those of us primarily used to working with http and browsers it's not immediately apparent that the http headers have no effect here.

from pdfkit.

jessamynsmith avatar jessamynsmith commented on July 27, 2024

In case this helps anyone else, I was having an issue, even with the doctype and html. What helped was changing my code to this:

import codecs
import pdfkit

input_filename = 'input.html'
output_filename = 'output.pdf'

with codecs.open(input_filename, "r", "utf-8") as f:
    html_text = f.read()
    pdfkit.from_string(html_text, output_filename)

from pdfkit.

sigmavirus24 avatar sigmavirus24 commented on July 27, 2024

@jessamynsmith this is the Ruby pdfkit project :)

from pdfkit.

jessamynsmith avatar jessamynsmith commented on July 27, 2024

Oops. Well, the doctype and html stuff still helped me. :)

from pdfkit.

sigmavirus24 avatar sigmavirus24 commented on July 27, 2024

No worries @jessamynsmith :)

from pdfkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.