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

UTF-8 Support #17

Closed
MartinHlavna opened this issue Oct 16, 2018 · 21 comments
Closed

UTF-8 Support #17

MartinHlavna opened this issue Oct 16, 2018 · 21 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@MartinHlavna
Copy link

MartinHlavna commented Oct 16, 2018

Hello,
I have encountered a problem with drawString method and utf8 characters. After calling for example

g.drawString('E.B. Lukáča');

, method throws exception. After debugging, it looks like there is support only for Latin1 which does not contain all characters I need. In this example it is letter 'č'. Is it possible to add UTF-8 support?

Thanks in advance.

@DavBfr
Copy link
Owner

DavBfr commented Oct 20, 2018

Please fill free to provide UTF-8 support to this library.

@DavBfr DavBfr added enhancement New feature or request help wanted Extra attention is needed labels Oct 20, 2018
@z2228391
Copy link

I would like to use Chinese character to print.
g.drawString(ttf, 20.0, '檯號', 10.0 * PDFPageFormat.MM, top - 10.0 * PDFPageFormat.MM);

Error message:
Invalid argument(s): String contains invalid characters.

Can anyone help?

@DanielSoCra
Copy link

I need this feature too 💯
Currently it seems like only ascii 2 is supported.

Any schedule for this feature?

Ps: thanks for sharing this with us!

@DavBfr
Copy link
Owner

DavBfr commented Dec 19, 2018 via email

@DanielSoCra
Copy link

There is already a branch that supports unicode.
I merged it into master on my local Repo and it works.

@MartinHlavna
Copy link
Author

@anondev32

Which branch is it please?

@DanielSoCra
Copy link

DanielSoCra commented Dec 20, 2018

There is an error aswell, you need to comment this line out:

#26 The branch is called unicode.

File stream.dart
Line 85

change it to:
// putBytes([0xfe, 0xff]);

@DavBfr
Copy link
Owner

DavBfr commented Dec 21, 2018

@anondev32 Can you output any string correctly using this branch? It is just missing the cmap database from the ttf fonts.

@DanielSoCra
Copy link

DanielSoCra commented Jan 3, 2019

I can output everything just fine. Altough i have a Problem viewing it in the original Adobe Reader, it works with i.e. Foxit Reader and Mobile devices.

I'm loading Fonts like this:

var bytes = await rootBundle.load("assets/Roboto-Regular.ttf");
var font = PdfTtfFont(document, bytes);

@DanielSoCra
Copy link

So, actually I debugged my app on iOS an their PDF Viewer has the same bug as Adobe's.
It shows those grey boxes around every letter.
If I knew how to fix it I would do it myself, but I don't really know where to start.

@DanielSoCra
Copy link

Another Update:

Creating the PDF is not the issue, the problem is with viewing it.
So regardless where I create the PDF (Android/iOS device), it displays correctly on Android, Desktop (Google Chrome, Foxit Reader) but fails in Adobe Reader or iOS PDF Viewer.

If I can help you in any matter please let me know I am eager to help.

Best regards

Daniel

@DavBfr
Copy link
Owner

DavBfr commented Jan 12, 2019

It is a complex change. We need font subsetting first I think to be able to reorganize the glyphs.

@DanielSoCra
Copy link

So, in the meantime, can you please provide us a way to use the PdfFont helvetica then?

The spacing between characters is too large for my usecase. I tried digging int o PdfFont.helvetica() and changing the widths, but nothing happens. Where can I adjust these settings for my needs?

@biancashouse
Copy link

If you store strings from the iOS kbd that are surrounded with single or double quotes, you can get forward and backward single and double quotes into your strings.

It took me a long time to figure out replaceAll on "'" and '"' was not working, because the actual chars stored were one of 8216, 8217, 8220, and 8221.

So something like this will replace them with a back quote...

String cleanString(String s) => s == null ? '' : s
.replaceAll("'", '') .replaceAll('"', '')
.replaceAll(String.fromCharCode(8220), '') .replaceAll(String.fromCharCode(8221), '')
.replaceAll(String.fromCharCode(8217), '') .replaceAll(String.fromCharCode(8216), '');

Probably a more elegant way, but I'm a java geek who is still in the dart early learning period.

BTW - Dave, will your new Text pdf widget do auto wrapping if its constrained ?

@DavBfr
Copy link
Owner

DavBfr commented Feb 19, 2019

@biancashouse Yes, the text widget auto-wraps.
Can you give me an example code to reproduce this bug? I don't understand what is the issue.

@DavBfr
Copy link
Owner

DavBfr commented Mar 24, 2019

Pdf version 1.3.5 implements that.

@DavBfr DavBfr closed this as completed Mar 24, 2019
@ethael
Copy link
Contributor

ethael commented Mar 28, 2019

Thanks a lot! We'll check it out.

@kiko555
Copy link

kiko555 commented Apr 4, 2019

I changed from 1.3.4 to 1.3.5, but the chinese word(utf8) still not work.
Do I need to do something after change to 1.3.5?

@DavBfr
Copy link
Owner

DavBfr commented Apr 4, 2019

You have to use a TrueType font that has the right glyphs you try to display.

@XbIK
Copy link

XbIK commented Apr 22, 2019

Is there any example of correct utf8 usage. I changed to 1.3.5 and use a True Type with cyrillic from assets, inhereit the font style from context, but still receive an error

@DavBfr
Copy link
Owner

DavBfr commented Apr 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

8 participants