setasign / tfpdf Goto Github PK
View Code? Open in Web Editor NEWThis class is a modified version of FPDF that adds UTF-8 support.
This class is a modified version of FPDF that adds UTF-8 support.
There's a new release based on FPDF 1.82 available: http://fpdf.org/en/script/script92.php
"message": "tFPDF::_putfonts(): Failed opening required '/var/www/<LARAVEL PROJECT>/storage/app/pdf/unifont/ttfonts.php' (include_path='.:/usr/share/php')", "exception": "Symfony\\Component\\Debug\\Exception\\FatalErrorException", "file": "/var/www/<LARAVEL PROJECT>/vendor/setasign/tfpdf/tfpdf.php", "line": 1896,
If i create an empty ttfonts.php where its searching, problem solves.
"Hello, world" = "Привет, мир!"
how can i bold a word inside a paragraph
Can I export Chinese files
As it took me quite a while to figure this out and the documentation seems to be gone, I'll try to summarize what I found:
tFPDF can use "built in" fonts, that is (to my understanding) whereever a PDF is going to be printed, there will be those fonts at minimum:
Courier, Helvetica (= Arial), Times, Symbol, Zapf Dingbats - including their bold and italics versions.
If you want other fonts, I would get them from Google Werbfont helper but you're fine with other fonts as long it's True Type - and remember that your particular glyphs (cyrillic, greek or the like) are included inside the TTF file if you want to print them!
You will have to place those font files as a True Type Font (.ttf) and only using small caps, no spaces in the filename inside a certain font folder. Usually, you need an extra file for bold and another one for italic letters. Where should that folder be placed?
If you install tFPDF via composer (as we should)
composer require setasign/tfpdf
or even otherwise, a font folder
vendor/setasign/fpdf/font
will be created, containing a subfolder "unifont"
However, for security reasons (vendor folder with PHP code not being directly reachable via a browser request) you should better be placing the "vendor" folder next to the "public" folder containing the web root - but that has nothing to do with tFPDF.
To put your own fonts inside the file tree "vendor" generated by composer is not such a great idea because if you delete that "vendor" folder without much thought in order to recreate it, your fonts will be gone.
Better set a custom font path in the PHP code, like
define('FPDF_FONTPATH', '/www/htdocs/mydomain/font/');
Then copy all the files from abovementioned default "font" folder here, then add your ttf file in the "unifont" folder inside "font", for example source-sans-3-v15-latin_latin-ext-regular.ttf
The "unifont" folder must contain the newest code file "ttfonts.php" from the software package, so remember to update that if composer updates the tftpd package!
My PDF generation code usually starts like this:
$pdf = new tFPDF($orientation = 'P', $unit = 'mm', $format = 'A4');
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->AddFont('SourceSans', '', 'source-sans-3-v15-latin_latin-ext-regular.ttf', true);
$pdf->AddFont('SourceSansB', 'B', 'source-sans-3-v15-latin_latin-ext-700.ttf', true);
$pdf->SetDisplayMode('real');
When tFPDF tries to access your TTF font for the first time, it has to calculate some metrics and produce special font files ending with .mtx.php , .cw.dat and .cw127.php - therefor the webserver must be able to write into that folder!
Also if you install a new version of a ttf file, delete the corresponding old files .mtx.php, .cw.dat and .cw127.php so they may get regenerated.
Maybe this is by design, but I'm wondering why the .gitignore
contains the line font/unifont/*.php
, when font/unifont/ttfonts.php
is required as an autoload
in composer.json
.
Maybe the point was to exclude generated files like font/unifont/dejavu.mtx.php
.
In that case, I would propose changing the .gitignore
line to read font/unifont/*.*.*
, which excludes *.cw.dat
, *.mtx.php
and *.cw127.php
, but not ttfonts.php
.
Background: I'm running into this because our project's code delivery basically does
composer install
git add --all .
git push production HEAD
Since this update, vendor/setasign/tfpdf/font/unifont/ttfonts.php
is excluded, which causes problems. I can fix this in other ways, but I wanted to raise this issue.
Hi,
An update has been made to the tFPDF script, could we get this repo updated to mirror the change please?
PHP8.2 was released few days ago. After migration, I got these errors:
A PHP Error was encountered
Severity: 8192
Message: Creation of dynamic property TTFontFile::$maxUniChar is deprecated
Filename: unifont/ttfonts.php
Line Number: 991
Backtrace:
File: /var/www/html/vendor/setasign/tfpdf/font/unifont/ttfonts.php
Line: 991
So, I think it would be better if the library can support PHP8.2.
Best regards.
First of all: thank you very much for this patch, it save me a lot of hours!
I just had a problem with the path to fonts used to generate the PDF in production, in a Symfony 3.4+ project. Path seems to be hard coded in *.php and *.dat files in font/unifont folder, as see in this answer from StacOverflow: https://stackoverflow.com/a/38520012/1866679
After removing the incriminated files, my PDF is generated as wanted under production server.
Is there a way to avoid this trouble or did I have to avoid those files to be uploaded under production?
Hi,
I'm using TFPDF since yesterday, before I was on FPDF (Big trouble with non-latin language).
I have fix the problem for Cyrillic language just with the change to tFPDF but others non-latin language still not working.
public function createPDF() {
$pdf = new tFPDF();
$pdf->AddPage();
// Add a Unicode font (uses UTF-8)
// $pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
$pdf->AddFont('DejaVu','','DejaVuSans.ttf',true);
$pdf->SetFont('DejaVu','',14);
$pdf->Write(8,'이것은 시험이다');
$pdf->Output();
}
I continue to have square instead of good characters.
What can I do to fix this ?
And I need to add this languages in my documents at any time, I don't know if my string could be with non-latin characters.
Thanks ! :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.