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

PDF Export with UTF-8 support #1539

Closed
marovargovcik opened this Issue Oct 28, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@marovargovcik

marovargovcik commented Oct 28, 2018

Is your feature request related to a problem? Please describe.
Right now Tabulator is using jsPDF under the hood. jsPDF unfortunately does not support UTF-8 by default. There is ongoing issue opened on Github MrRio/jsPDF#12

Describe the solution you'd like
Would be super cool if Tabulator can use something more "production" ready with all common features built in.

Describe alternatives you've considered
Maybe we can use pdfMake? https://github.com/bpampuch/pdfmake

Workaround
This is for users of Tabulator that are also struggling how to output special characters to your PDF exported by Tabulator. There is an option to add custom font to PDF with UTF-8 support.
Here is how you can do it:

tabulatorInstance.download("pdf", "data.pdf", {
  autoTable: function(doc) {
    doc.addFileToVFS("yourFont.ttf", "AAEAAAAUAQA..."); // your font in binary format as second parameter
    doc.addFont("yourFont.ttf", "yourFont", "normal"); 
    doc.setFont("yourFont");
    return {
      styles: {
        font: "yourFont",
        fontStyle: "normal"
      }
    };
  }
});

Why is this workaround bad?
Providing font in binary is resulting, in my case, in loading unnecessary 277kb.

@olifolkerd olifolkerd self-assigned this Oct 28, 2018

@olifolkerd olifolkerd added the feature label Oct 28, 2018

@olifolkerd

This comment has been minimized.

Owner

olifolkerd commented Oct 28, 2018

Hey @marovargovcik

Thanks for getting in touch.

The lack of UTF-8 support is an issue, i agree with you there.

At the moment the PDF downloader is depended on the autotable plugin, which is in-turn dependent on the jsPDF plugin.

As with version 4.1 to be released shortly including more updates to the downloaders i would be unable to bring in a change soon as i don't want to force users to have to make whole sale changes to their code too often. but it is certainly something i would be interested in perusing later down the line.

That being said, it is very easy to implement your own custom downloaders, so if you came up with a viable solution based on a different library that used the same design pattern as the existing downloader i would be happy to look at including it in Tabulator.

In the mean time i will update the documentation to highlight the UTF-8 support issue, and with your permission include your workaround in the documentation if you would be happy with that.

Thanks for getting in touch,

Cheers

Oli :)

@marovargovcik

This comment has been minimized.

marovargovcik commented Oct 28, 2018

Thanks for your response @olifolkerd,

I understand. And yes, you can use my example in the documentation but please be aware that not all fonts I tried to implement worked. Ubuntu fonts worked without problem but Roboto did not. Some of them work and some don't. I have very poor knowledge of how encoding and all these things about fonts work under the hood so I don't see a pattern why certain fonts are not working.

Best regards.

@olifolkerd

This comment has been minimized.

Owner

olifolkerd commented Nov 4, 2018

I have added a note about this in the docs and included a link to this issue incase it is helpful to others.

Thanks for the workaround.

Cheers

Oli :)

@olifolkerd olifolkerd closed this Nov 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment