I'm trying to make my text underlined in FPDF but it seems to be impossible... I'm not using HTML. I'm using an DejaVu unicode font, which supports UTF-8, and also its my first time working with the FPDF.
Is that even possible? Please give me some solutions.
Try this :
$fpdf->SetFont('Dejavu','U'); //Where "U" means underline.
See also (in german) http://www.fpdf.de/funktionsreferenz/?funktion=SetFont
See also (in english) http://www.fpdf.org/en/doc/setfont.htm
Related
I am trying to export to PDF using FPDF and TCPDF php library. I found that the emojis like 😁 😀 💃🏻 ❤️ 🥳 where not converted. Only ️️some rectangle box there in generated pdf. I also tried tfpdf.
$text = "There is my text 😁 , 😀 and emojis 💃🏻 ❤️ 🥳";
require('tfpdf/tfpdf.php');
$pdf = new tFPDF();
$pdf->AddPage();
//Add a Unicode font (uses UTF-8)
$pdf->AddFont('Segoe UI Symbol','','seguisym.ttf',true); // DejaVuSans.ttf
$pdf->SetFont('Segoe UI Symbol','',12);
$pdf->Write(8,$text);
$pdf->Output();
I also tried different font. But didn't work for me. Can any one help me in this regard?
Sadly fPDF, TCPDF nor tFPDF can't print those characters. Issue is, these characters are not part of BMP, they are expressed with surrogate pairs, meaning they behave like multiple characters in UTF-16 (because of that one emoticon is printed as 2 rectangle boxes, not one) and also they have codepoint above 65535. However all mentioned PDF libraries relies on codepoint index being <= 65535 as well as TFontFile class reading TTF files.
You would also need to add TTF file having complete set of Unicode charset, or at least emoticons. Most fonts does not have it. This brings another issue for PDF library, which would probably need to have support for fallback font, which will be used when codepoint is not found in main font (for example you want to print text in Gotham, but since that does not include emoji, use other font for them). Btw for example emoji font "Noto Color Emoji" has 23 MB TTF file. So it gets big easily.
Anyway, all of the above can be added to PDF libraries, but it will require some effort. I am planning to do it for my needs as well sometimes. I think it will take roughly 1 man day.
Alternativelly, you might try something more robust like mPDF, but that library is huge, slow and require complete rewrite of your fPDF code. Also can't guarantee it can print emojis as well.
I am using fpdf in php for developing pdf. I have to include some static Arabic or Farsi text to this pdf. I had used
$farsi_txt = iconv('UTF-8', 'ISO-8859-5', html_entity_decode('حضور محترم'));
$pdf->Write(5,$farsi_txt);
But the output was Blank.
When I had displayed it directly
$pdf->Write(5,'فغانستان کابل');
then the out put was like ٕغانستان کابل
When I had created a window to insert the arabic text to database then the output was حضور محترم
Is there any way to display this text as Arabic or Farsi in fpdf?
Found the answer for my question. I had replaced FPDF with TCPDF. TCPDF provides special fonts for Arabic and Farsi languages. I had got the correct output using TCPDF. I simply done this by switching font and $tpdf->setRTL(false); this sets the right to left alignment if arabic words.
TCPDF Download link
take a look here. This page specifically talks about adding new Fonts and encodings, which I believe is the issue as the PDF is missing the Arabic font and is unable to find a replacement for characters.
The following Symbols prints well in an MS Excel spreadsheet when outputting using VBA:
Sub print_chrw_sub()
Dim a1
a1 = "&H27E6"
ActiveCell.Offset(1).Value = ChrW(a1)
Dim a2
a2 = "&H27E7"
ActiveCell.Offset(2).Value = ChrW(a2)
End Sub
Output:
⟦
⟧
However, when I am using the symbols in a PHP code, the sybols look like square blocks within the code as well as on a web browser - also in the current usage above. Example:
<?php
echo $str1 = "⟧"
?>
I am using UTF-8 encoding.
On the flip side the following sybols are printing correctly in PHP code as well as on a web browser:
chrW(&H22A4)
Output:
⊤
chrW(&H22A5)
Output:
⊥
Thanks for any help.
The character you refer as chrW(&H27E7) is known as the Mathematical right white square bracket (or U+27E7).
When it is displayed in Excel, the font displayed is probably Calibri or Arial, but these fonts actually don't support this character.
And that's where font substitution steps in: to provide a font wich will correctly handle the character.
If you look at this page, you will see which fonts on your system actually support U+27E7. On my system there is only two: Cambria Math and Segoe UI Symbol.
If you see a square symbol (□), it means that font substitution didn't work correctly. For the PHP source, it is not very important, because the correct character will actually be there (provided the encoding is set up correctly).
For the HTML code, you should consider setting a font which you know support this character, be keep in mind that local fonts (the ones installed) differ vastly between two systems. You may want to use the CSS font-face to provide a web font.
I'm using TCPDF in Codeigniter to generate PDF file.
I have link from 'view' to 'controller' function that contains parameters. One parameter is name = 'Högskolan'.
When I get this parameter in controller and display in PDF sometimes it's displayed like 'Högskolan', sometimes like 'Hgskolan'(missing swedish character). This issue happens only in IE (sometimes - not always).
Also there are differences when I save this file with File->Save as and File->Save.
With first option the file is saved as 'Hgskolan.pdf', with the second as 'Högskolan.pdf'.
What can caused these issues? Any idea?
Thanks.
I would suggest doing something like this: Convert accented characters to their plain ascii equivalents
You will find it works better to output without the accents (provided it doesn't substantially change the word of course).
As anttir suggested it's probably a browser specific issue or system issue not liking the characters. Can you test output on another browser or another platform to isolate the issue.
I'm not 100% sure if it's TCPDF tripping you up there, or the browser. You can test that with something like Fiddler (http://fiddler2.com/) or Charles (http://www.charlesproxy.com/) [both debugging proxies].
I have a government client that requires the legal 'section symbol' (§) in their documents. When creating the documents in a web page, this symbol is created with § or §.
I can not figure out how to get either of these to work in a pdf document created with FPDF. I have tried the iconv and utf8_decode methods, but neither have worked. Any ideas?
You're looking for html_entity_decode().
There is an easier approach to do this:
You can generate a section symbol using FPDF with using ascii code: chr(167).
It's good practice to make this a constant. At the top of your script, add:
define('SECTION',chr(167));
Now you can use SECTION in your script to print the euro symbol.
For example:
echo SECTION.'1.1';
Will output: §1.1
Note: This will also work for other symbols with chr(ascii), where ascii is the ascii code of the symbol. You can find an overview of ascii codes on this page: http://www.atwebresults.com/ascii-codes.php?type=2