Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utf8 support #12

Closed
shkuropat opened this issue Apr 11, 2012 · 166 comments
Closed

Utf8 support #12

shkuropat opened this issue Apr 11, 2012 · 166 comments

Comments

@shkuropat
Copy link

Is it posible to use non-latin (e.g. cyrillin) characters?

@dvdotsenko
Copy link
Collaborator

As of June 2012 jsPDF still does not support the version of Unicode (UCS-2 BE / UTF16 BE) PDF format allows. This means, that almost all characters outside of ASCII are pretty much broken. There are plans to add support for UCS-2 streams to jsPDF, maybe somewhere over this summer - 2012. It's a lot of work.

@dvdotsenko
Copy link
Collaborator

Nowhere at this time. It's still too much work. Unicode will not be here until code is added to support embedding (and subsetting) unicode fonts within PDF. That alone is a gargantuan task and a logistics issue since it involves pulling binary blobs into browser and it inflates the size of PDF.

Unless someone with a skill really needs this, or some party is willing to sponsor this move, it's unlikely to happen naturally.

@sguzgon
Copy link

sguzgon commented Dec 3, 2012

Ok. It would be good to have support for UTF-8. I'll have to find some alternative. Thanks!

@bluebluesky
Copy link

Dear Dvdotsenko :
How about the UTF8 support now? I also failed to show Chinese with jspdf . Jspdf is such a good tool , it's so pity. So could u give me some suggestions how to solve this issue?

Thanks in advance
jessie

@zeligmanos
Copy link

any news about Unicode support? jsPDF is really fantastic tool but without Unicode support it's extremely limited...

@Mulegoat
Copy link

@dvdotsenko when you say 'almost' all characters, would that include UL list items like a disc? This seems like the most basic character requirement which i cannot get with ASCII encoding. All bullets get stripped out of the PDF when using the fronHtml method. Is there any kind of work around to include this character?

@kingdom91
Copy link

What about Cp1250 ? Is there any chance to support?

@deedarb
Copy link

deedarb commented Mar 5, 2014

Unfortunately can not use for production without UTF-8 support

@PrakashInn
Copy link

When it could be supported ? . utf-8 support is needed desperately.

@albinotonnina
Copy link

I was so sure about utf-8 support...I didn't check and I started using the library. Damn.

@defel
Copy link

defel commented Mar 10, 2014

strange, had utf-8 support on my prototype, but its gone as soon I use it on production ..

Is there are any plugin or lib I forgot to include?

@MrRio
Copy link
Member

MrRio commented Mar 10, 2014

There's a fair few characters that appear to work. Full unicode support
isn't in there though. It's something that we're working on.

On Mon, Mar 10, 2014 at 5:47 PM, defel notifications@github.com wrote:

strange, had utf-8 support on my prototype, but its gone as soon I use it
on production ..

Is there are any plugin or lib I forgot to include?


Reply to this email directly or view it on GitHubhttps://github.com//issues/12#issuecomment-37211898
.

James Hall
Director

Parallax

+44 113 322 6477
http://parall.ax/

Registered office: The Old Brewery, High Court, Leeds, LS2 7ES
Registered in England no. 07430032
VAT No. 101 3405 84

@defel
Copy link

defel commented Mar 10, 2014

Ok, I forgot to include the file jspdf.plugin.standard_fonts_metrics.js .. everything works again as in my prototype

@legikaloz
Copy link

@defel Can you post a code snippet how do you create documents with utf-8 support?

@luciash
Copy link

luciash commented Apr 18, 2014

@defel I wonder how you made UTF-8 working by including jspdf.plugin.standard_fonts_metrics.js too. It does not work for me with "ěščřžýáíé". (result is the same as without that plugin: "šYžýáíé")

@defel
Copy link

defel commented Apr 22, 2014

@luciash as @MrRio wrote, there is no thing like UTF-8 support in jsPDF. But some basic unicode characters work, like ü or ².

@djbu
Copy link

djbu commented May 18, 2018

It is too complicated to put in the readme that it doesn't accept utf-8 yet? The idea is to help the other devs, right?

@asalhani
Copy link

@arasabbasi if you want, share with us your progress, and let's know if we can help to make this evil see the light. At the end, the idea of open source is to let other contribute.
Good luck

@eddieklc
Copy link

image

Well, technically, he didn't lie. He never said which Monday he's talking about.
This issue is opened since 2012...
Completely amateur work, dude don't call yourself a developer.

@Uzlopak
Copy link
Collaborator

Uzlopak commented May 18, 2018

@asalhani
It is in the repo. You just have to build it. And in the version of March 3rd it was buildable. So I don't hide any progress. And if you claim that you wait 6 years for this feature, then I highly doubt this.
So yeah..

@eddieklc
Well. Then don't call me a software developer. Who cares? But be aware of the fact, that I am not paid by you or any other person on this project. And just because this issue is made in 2012 doesn't mean that anybody is obliged to fix or realize it.
I could write so much, but at the end it is not important, because you have nothing to say in this case.

Best Regards
Aras

@prnxdev
Copy link

prnxdev commented May 21, 2018

We will be very grateful if you could release fix with UTF-8 support <3 :)

Also I suggest that you should create profile on Open Collectives or Patreon to get some funds cause this library / package is pretty dope. It helps a lot and I think you deserve to get some money for that!

@Uzlopak
Copy link
Collaborator

Uzlopak commented May 21, 2018

Hello @pawel-miczka

It has nothing to do with getting paid. We are all here softwaredevelopers doing this in our free time. And we have a social life and are all busy. And when I get called a liar for something which is not in my powers, than I think that some people expect us to be their slaves, or what?

@MrRio
Copy link
Member

MrRio commented May 21, 2018

Now shipping in 1.4.0 🎉

@MrRio MrRio closed this as completed May 21, 2018
@prnxdev
Copy link

prnxdev commented May 22, 2018

Will you update documentation on how to set this up or could you send here some example because now I'm using 1.4.0 and I still don't have polish letters? Thanks anyway for update 👍

@Uzlopak
Copy link
Collaborator

Uzlopak commented May 22, 2018

If you want to use polish letters and if they are not part of ASCII you have to add a font which contains the polish letters-

Go To /examples/basic.html and check out the last tab "Using Fonts"

@aonzuza
Copy link

aonzuza commented May 25, 2018

How do I add ℃ to my pdf ? I have tried to search for an example, but nothing was found. Thks for your effort to develop this library !!!!

@aelkoussy
Copy link

@arasabbasi to add a font that contains (some utf-8) letters, can you point to what is the proper way to add it ? it is not clear in the document if I should use addFont or setFont , thanks

I am trying to add fonts that support Arabic (like sans-serif for example)

@lukkor89
Copy link

@arasabbasi how You get the variable - PTSans value from examples/basic.html ?
Is this some kinda hash that we can generate from googlefonts?

@kelly-tock
Copy link

is there any way to do a fallback font? the data I need to render in a generated pdf is dynamic, so some could be in spanish, some in japanese, etc.

@daryl-z
Copy link

daryl-z commented Aug 25, 2018

full base64 encoded ttffile is too big.....

@jimfilippou
Copy link

Day 2000... still no fix 😆

@Uzlopak
Copy link
Collaborator

Uzlopak commented Sep 10, 2018

Yeah, so what?

I added a font converter. I wrote last week a HTML-plugin which is custom fonts compatible and all that stuff last week. I rework right now the documentation generation. You can see under projects the jsPDF 1.4.2 issues which have to be solved till then and what I fixed till now.

https://github.com/MrRio/jsPDF/projects/4

Three big issues for jsPDF 1.4.2

Better ttfsupport, better Arabic support and an error in the text method.

So yeah. If you want you can participate. Everybody is invited to provide some good code and please don't forget the unit tests. Then we will have 1.4.2 in no time

@msylw
Copy link

msylw commented Sep 16, 2018

Just my 2c, for those not afraid to go async. The base64 encoder is not mine, but can't find the original source anymore... This uses promises to download the font files and jspdf asynchronously, and set up everything in the browser.
Pros: fonts don't need preprocessing, can be transferred as binaries, easy to add more
Cons: requires async code, fetch requests may need some extra parameters to work

Note, this is a little awkward way to use it when pulled out of context, but the actual idea should be easy to adapt.

    function getBase64(file) {
      return new Promise((resolve, reject) => {
        const reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = () => resolve(reader.result);
        reader.onerror = error => reject(error);
      });
    }

    let pFont = fetch("/fonts/font.ttf")
      .then(response => response.blob())
      .then(response => getBase64(response))
      .then(response => {
        return response.split(',')[1];
      });

    let pFontBold = fetch("/fonts/fontBold.ttf")
      .then(response => response.blob())
      .then(response => getBase64(response))
      .then(response => {
        return response.split(',')[1];
      });

    let pClass = import('jspdf');

    Promise.all([pFont, pFontBold, pLogo, pClass])
      .then(([font, fontBold, jsPDF]) => {
        let pdf = new jsPDF();
        pdf.addFileToVFS('Font.ttf', font);
        pdf.addFileToVFS('FontBold.ttf', fontBold);
        pdf.addFont('Font.ttf', 'font', 'normal');
        pdf.addFont('FontBold.ttf', 'font', 'bold');

        // add stuff to the pdf
        pdf.setFont('font');
        pdf.text(....);
        pdf.setFontStyle('bold');
        pdf.text(....);
        pdf.setFontStyle('normal');
        pdf.text(....);
    });

@satyakshi27
Copy link

How to use font for hindi text using jspdf version 1.4.0
..any idea??
@arasabbasi

@drbdvd
Copy link

drbdvd commented Oct 6, 2018

I've managed to produce PDFs with Hebrew. Used Arimo font (converted to Base64 online and stored as const in code) and of course added a reversing function of my own to support RTL.

reverseHebrew(str) {
var splitString = str.split("");
var reverseArray = splitString.reverse();
return reverseArray.join("");
}

Thanks @arasabbasi

@andreathniah
Copy link

For some reason, UTF-8 support for doc.text() using the examples from /examples/basic.html is doable for me, but once changed to doc.fromHTML(), the whole thing breaks apart. Is there anyone who has an example for doc.fromHTML()?

@Uzlopak
Copy link
Collaborator

Uzlopak commented Oct 10, 2018

fromHTML is deprecated and will not be getting any updates or support. We will have a new html 2 pdf method in the next release.

@sgh-mohamed
Copy link

sgh-mohamed commented Oct 19, 2018

@arasabbasi I used a custom font that contains polish letters but still got in the output the weird character þÿ .
when i use '.text' it's fine but in the parts where i use '.fromHTML' i got the weird character.

@makrand1234
Copy link

Now shipping in 1.4.0 🎉

Hi Mr. Rio,

I am not sure what is shipped in 1.4.0. Does this mean that the library is supporting UTF-8 from 1.4.0 onwards? Please clarify.

@Uzlopak
Copy link
Collaborator

Uzlopak commented May 15, 2019

Locking to reduce possible Spam.

@parallax parallax locked as spam and limited conversation to collaborators May 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests