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

Fix handling UTF-8 characters in FpdfOutput and TcPdfOutput #137

Closed
wants to merge 3 commits into from

Conversation

KamilPesek
Copy link

@KamilPesek KamilPesek commented Jul 20, 2021

Fixes #131

@sprain
Copy link
Owner

sprain commented Jul 20, 2021

Thank you!

The style guide states:

The following sans-serif fonts are permitted:
– Arial
– Frutiger
– Helvetica
– Liberation Sans

Therefore I don't think we should allow the font to be as flexible as this pr makes it.
Maybe we could instead provide a utf8-compatible font which is fixed within this library. What do you think?

@sprain sprain added the needs-work This pr needs some more work to be ready label Jul 21, 2021
@KamilPesek
Copy link
Author

KamilPesek commented Aug 20, 2021

I have to say I am lost. I tried to played with FpdfOutput but with no success. I tried some test code like
image
( I tried to add custom Helvetica and Frutiger generated from ttf from here http://www.fpdf.org/makefont/make.php)

Font has been added, font is also set (I can see it's used) but it has still problem with ěčřšžýýáíé
image

EDIT: Ok, so I was on false lead. Problem was in this library. I added convertText() which I believe could fix it.

@KamilPesek
Copy link
Author

@sprain how should I proceed?

@sprain
Copy link
Owner

sprain commented Oct 11, 2021

I gave this PR a try.

I used the name Pia-Maria Mareč with FpdfOutput and got Pia-Maria Mareè in the pdf. So I doubt this is actually a fix for the issue.

@sprain sprain changed the title Added possibility to change FONT for PDF outputs Fix handling UTF-8 characters in FpdfOutput and TcPdfOutput Oct 11, 2021
@KamilPesek
Copy link
Author

Hm, thinking what could be the difference:
image

I am on Windows 10, CRLF

$fpdf = new \Fpdf\Fpdf('P', 'mm', 'A4');
$fpdf->AddPage();

$output = new FpdfOutput($qrBill, 'de', $fpdf);
$output
    ->setPrintable(false)
    ->getPaymentPart();

@$qrPdfTempPath = tempnam('tmp', 'test.pdf');
$fpdf->Output($qrPdfTempPath, 'F');

header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $qrPdfTempPath . '"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
echo file_get_contents($qrPdfTempPath);

@sprain
Copy link
Owner

sprain commented Oct 13, 2021

Looking around it seems that utf8 and FPDF is basically a big pain. Because of stuff like this I use html and convert it with PrinceXML into pdfs in my projects. It just works :)

Maybe one could try tFPDF instead?
https://github.com/Setasign/tFPDF

Also, maybe @Franco2911 has an idea, who provided the original FpdfOutput for this library?

@sprain sprain added the help wanted Extra attention is needed label Oct 13, 2021
@Franco2911
Copy link
Contributor

Hello,
I use utf8_decode() to use utf8 characters.
My textes cames from database.

a little example maybe can help.

$this->Cell(0,0, utf8_decode($address->getName()));

@KamilPesek
Copy link
Author

KamilPesek commented Oct 14, 2021

I use utf8_decode()

That's what I had to replace to make it work. The question is why it works differently for me. I also tried it on our Linux server and it also works there.

@sprain
Copy link
Owner

sprain commented Oct 15, 2021

Looks like we're kinda stuck here 🤔
New ideas are welcome.

@Franco2911
Copy link
Contributor

I made many and many tests before a good result.

Your entire flow must be UTF8 compliant.

You have to use utf8 decode on each rows(cell and multicell)

@sprain
Copy link
Owner

sprain commented Dec 18, 2022

Closing this due to missing activity. Feel free to re-open if there is a need.

@sprain sprain closed this Dec 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed needs-work This pr needs some more work to be ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TcPpdfOutput and FpdfOutput do not support full utf-8 character set
4 participants