Difference between #216 and #217 of
Yii v2 snippet guide

Revision #217 has been created by rackycz on Aug 5, 2020, 10:43:00 AM with the memo:

FPDF
« previous (#216) next (#218) »

Changes

Title unchanged

Yii v2 snippet guide

Category unchanged

Tutorials

Yii version unchanged

2.0

Tags unchanged

tutorial,beginner,yii2

Content changed

[...]
xdebug.remote_autostart=on
```

Quotes were not important. I didnt even need to [download](https://xdebug.org/download) current version of xdebug, it was already in folder C:\xampp\php\ext.

**PDF
 - no UTF, only English chars** --- For creating PDFs I uscan be [FPDF](http://www.fpdf.org) library. It it extremely simple to make it run. Just download it and then use it as a helper - I described how this is done [above](https://www.yiiframework.com/wiki/2552/yii-v2-snippet-guide#creating-your-new-helper-class). Do not forget to add namespace to the PHP file.

You will only need **FPDF.php** and folder **font**. Then in your controller just do this:
[...]
Note: I renamed original file fpdf.php to FPDF.php

The only disadvantage is that UTF cannot be used and conversion to older encodings is required. For Czech Republic all texts must be converted like this:
 
 
```php
 
private function convertUtf8ToWin1250($value) {
 
  $value = trim($value);
 
  if (strlen($value)==0) {
 
    // Warning:
 
    // Method strlen() returns number of bytes, not necessiraly number of characters.
 
    // Usually it is the same, but not always.
 
    // see also mb_strlen()
 
    return '';
 
  }
 
  return iconv("UTF-8", "WINDOWS-1250//IGNORE", $value );
 
}
 
```
 
 
A discussion is available [here](https://stackoverflow.com/questions/6334134/fpdf-utf-8-encoding-how-to).
 
 
**PDF - UTF, all chars**
 
---
 
 
When you need non-English characters, [tFPDF](http://www.fpdf.org/en/script/script92.php) should be used. Just download it and then use it as a helper - I described how this is done [above](https://www.yiiframework.com/wiki/2552/yii-v2-snippet-guide#creating-your-new-helper-class).
 
 
Summary: 
 
- Download tFPDF and unpack it.
 
- use file **tfpdf.php**
 
- and folder **font** .. it contains file **ttfonts.php** !!
 
- Into both mentioned files add your namespace which you are using for your helpers. Explained above.
 
7 0
4 followers
Viewed: 274 895 times
Version: 2.0
Category: Tutorials
Written by: rackycz
Last updated by: rackycz
Created on: Sep 19, 2019
Last updated: a year ago
Update Article

Revisions

View all history