jsPDF-AutoTable icon indicating copy to clipboard operation
jsPDF-AutoTable copied to clipboard

jsPDF-AutoTable don't support utf8?

Open duykhanh1411 opened this issue 8 years ago • 20 comments

I need add some char (ex: € ... ) on list but it break font like þÿ I was try add custom font, it only work on jsPDF (not work on jsPDF-AutoTable) Do you have any solution for this?

duykhanh1411 avatar Sep 22 '18 08:09 duykhanh1411

I'm having the same problem and the "þÿ" character appears. This also affects letter spacing and causes the text to get out of the cell. The same code worked with jsPdf v1.3.3 and AutoTable v2.3.2.

in my case the following characters are producing the issue: ”“

Update: After further investigation I noticed the issue is produced directly by jsPdf. Example of the problem:

            var doc = new jsPDF();

            doc.setFontSize(10);
            doc.text("“Simple demo”", 14, 16);
            doc.save('doc.pdf')

mdprw avatar Sep 28 '18 14:09 mdprw

@duykhanh1411 Can you create a minimal example of the issue?

simonbengtsson avatar Oct 28 '18 16:10 simonbengtsson

The problem is that I dropped for unicode support in version 1.4.0 in the .text Method the noBOM flag. So all non-ANSI chars are getting ab BOM resulting in this. So actually the issue is, that duykhanh1411 doesnt use a custom font, which has the '“' and the '”' character. I will add the noBOM flag to the text method back i think. Still needs some testing tho

Uzlopak avatar Nov 08 '18 08:11 Uzlopak

@simonbengtsson, example https://plnkr.co/edit/Qaqq2Nw2T98DWB5AzPXn?p=preview html: image pdf file: image

Tronghoang avatar Dec 18 '18 09:12 Tronghoang

Same issue

doc.addFileToVFS('Kanit-Regular.ttf', Kanit) doc.addFont('Kanit-Regular.ttf', 'custom', 'normal'); doc.setFont('custom');

image

mesiora avatar Dec 21 '18 06:12 mesiora

I tried now with the custom font Amiri as examplified in the jspdf docs and everything seems to work fine, could elaborate what doesn't work?

simonbengtsson avatar Jan 05 '19 14:01 simonbengtsson

It seems that AutoTable doesn't support utf8 based on following code example: http://jsbin.com/fufafotoji

mr-rahimi avatar Apr 11 '20 09:04 mr-rahimi

@mr-rahimi Where did you get this autoTable options from?

Just replace it with this :

  doc.autoTable({
    head: [['سلام']],
    body: [['مرحبا'], ['مرحبا']],
    styles: {
      font: 'Amiri',
      fontStyle: 'normal',
    }
  })

mmghv avatar Apr 11 '20 10:04 mmghv

@mmghv Thank you, Mohamed, for your comment. honestly, I didn't read the AutoTable options from its official documentation, but I read it from the PrimeNG report example.

mr-rahimi avatar Apr 12 '20 12:04 mr-rahimi

@mr-rahimi Where did you get this autoTable options from?

Just replace it with this :

  doc.autoTable({
    head: [['سلام']],
    body: [['مرحبا'], ['مرحبا']],
    styles: {
      font: 'Amiri',
      fontStyle: 'normal',
    }
  })

Thank you, but it seems, jsPDF doesnt work with table function : https://stackoverflow.com/questions/64183071/how-to-generate-utf-8-tables-in-jspdf , and it seems there is no autoTable in jsPDF itself.

SeyyedKhandon avatar Oct 03 '20 10:10 SeyyedKhandon

The same issue for me. It is really weird. I don't have any utf-8 character, but it break font like þÿ. "þÿ" is added in front of the table content. I'm using the latest version of jspdf and jspdf-autotable. The others look fine, but only breaks in this one. I'm attaching the screenshot below. image

Please help me to solve this issue. Thanks!

0xcodecrafterx avatar Nov 15 '20 00:11 0xcodecrafterx

Same thing here. Using latest versions. I made html - table and added it to doc: autoTable(doc, { html: '#myTable', startY: 440});

Seems like "-" char breaks that cell.

image

JalmariO avatar Nov 19 '20 11:11 JalmariO

Same thing here. Using latest versions. I made html - table and added it to doc: autoTable(doc, { html: '#myTable', startY: 440});

Seems like "-" char breaks that cell.

image

I was able to fix it by adding a custom font. Please inspect your html and check which font it uses. And then add that font to the jspdf.

0xcodecrafterx avatar Nov 19 '20 11:11 0xcodecrafterx

I was able to fix it by adding a custom font. Please inspect your html and check which font it uses. And then add that font to the jspdf.

I tried to change my table in html to font-family: 'helvetica' and used this same font in jspdf. This did not help. Maybe I have to try to use custom fonts then.

JalmariO avatar Nov 19 '20 12:11 JalmariO

I was able to fix it by adding a custom font. Please inspect your html and check which font it uses. And then add that font to the jspdf.

I tried to change my table in html to font-family: 'helvetica' and used this same font in jspdf. This did not help. Maybe I have to try to use custom fonts then. https://stackoverflow.com/questions/26908266/custom-font-faces-in-jspdf#:~:text=To%20add%20the%20font%20to,js%2DFile%20to%20your%20project. This is how to add a custom font to jspdf. This one is the perfect tutorial to add custom font to jspdf. https://www.devlinpeck.com/tutorials/jspdf-custom-font#:~:text=Adding%20Custom%20Fonts%20to%20jsPDF,of%20your%20desired%20font%20file.&text=Once%20you%20have%20your%20.,to%20this%20jsPDF%20Font%20Converter. I'm using 'Lato' font and solved the issue.

0xcodecrafterx avatar Nov 19 '20 12:11 0xcodecrafterx

https://stackoverflow.com/questions/26908266/custom-font-faces-in-jspdf#:~:text=To%20add%20the%20font%20to,js%2DFile%20to%20your%20project. This is how to add a custom font to jspdf.

Thanks for that. I would like to avoid using custom-fonts because I don't really need to. I tried to change the font for whole app to "Helvetica" and then "Arial". Then tried to use those fonts with jspdf also. Still that column with "-" - sign breaks. I am using angular material classes thou, could that be an issue on here...

JalmariO avatar Nov 19 '20 13:11 JalmariO

I don't quite understand the problem, but it seems that angulars PercentPipe formed the number so that minus - sign breaks the autotable... I was able to get it right using .toFixed(2) + %. I guess it has something to do with hyphen vs minus, but I tried replacing hyphens, but it did not help.

JalmariO avatar Nov 19 '20 18:11 JalmariO

my solution this problem:

  1. create custom font ( use this : https://www.devlinpeck.com/tutorials/jspdf-custom-font#:~:text=Adding%20Custom%20Fonts%20to%20jsPDF,of%20your%20desired%20font%20file.&text=Once%20you%20have%20your%20.,to%20this%20jsPDF%20Font%20Converter )
  2. add font to project : image
  3. set font: image
  4. use in project )

ghost avatar Mar 11 '21 07:03 ghost

Hey guys I applied this article https://www.devlinpeck.com/content/jspdf-custom-font#:~:text=Adding%20Custom%20Fonts%20to%20jsPDF,of%20your%20desired%20font%20file.&text=Once%20you%20have%20your%20.,to%20this%20jsPDF%20Font%20Converter

and then this code with style object(it's important)

doc.autoTable({ head: ..., body: ... styles: { font: 'Roboto-Regular', fontStyle: 'normal', } })

also don't forget doc.setFont("Roboto-Regular", "normal") -> it works for title

It works!

mertcankose avatar Aug 04 '23 15:08 mertcankose

stumbled across this and didn't have luck with changing fonts... my problem was originating from using d3-format, which uses U+2212 for its 'minus' symbol... the fix was to do the following: .replace(/[\u2212]/g, '-')

laventnc avatar Mar 28 '24 17:03 laventnc