TCPDF is an open source PHP class for generating PDF documents. It is easy to install and setup as well as many options available. There are few things worth to be noticed in my experience of usage. Here are some:
1. Installation
To install TCPDF class is easy.
- Download all files from TCPDF’s github.
- Create a directory
class
under the main directory of the Site. - Create a directory
class/tcpdf
. - Copy all files to
class/tcpdf
. - Add a line of code in the beginning of the php file:
require_once "class/tcpdf/tcpdf.php";
- Have fun!
2. Traditional Chinese support
The default setting of TCPDF does not support Traditional Chinese character because it lacks of fonts in Traditional Chinese. We have to add the font files manually.
- Download font file ‘Droid Sans Fallback’ and ‘msungstdlight’.
- Add two font files to
class/tcpdf/fonts
. - Open
config/tcpdf_config.php
and change two settings:define ('PDF_FONT_NAME_MAIN', 'helvetica'); to define ('PDF_FONT_NAME_MAIN', 'msungstdlight');
define ('PDF_FONT_NAME_DATA', 'helvetica'); to define ('PDF_FONT_NAME_DATA', 'msungstdlight');
p.s Here explains how to generate TrueTypeUnicode font files from DroidSansFallback.ttf font file.
3. A bug fixed while using PHP 7.2
When using PHP 7.2, TCPDF version 6.2.12 shows the error message:
Deprecated: The each() function is deprecated.
This message will be suppressed on further calls in /Users/xxx/Sites/mini_shop/class/tcpdf/tcpdf.php on line 16544
TCPDF ERROR: Some data has already been output,
can't send PDF file
Since each() function is deprecated after PHP version 7.2, the code must be modified in order to fit the new version. Fortunately, somebody has posted the solution. It works again just to replace three lines of code in tcpdf.php
as follows:
- while (list($key, $val) = each($prop)) {
+ foreach($prop as $key => $val) {
- while (list($id, $name) = each($attr_array[1])) {
+ foreach($attr_array[1] as $id => $name) {
- while (list($id, $name) = each($style_array[1])) {
+ foreach($style_array[1] as $id => $name) {
Replace each()
function with foreach()
function, and that’s it!
It is possible to put in and also create along with many choices accessible. You can find Digital Ocean vs AWS a handful of items well worth being seen if you ask me regarding use.
ReplyDelete