Skip to content

Commit bdc9712

Browse files
committed
Updated pdf dependencies for using unicode fonts
1 parent df02f05 commit bdc9712

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"smarty/smarty": "Use this package to render Smarty views via SmartyView",
4444
"nao-pon/elfinder-nightly": "Use this package to integrate elFinder with MediaController",
4545
"eventviva/php-image-resize": "Use this package to resize images using Smarty plugins",
46-
"setasign/fpdi-fpdf": "Use this package to generate PDF files",
46+
"setasign/fpdi": "Use this package to generate PDF files",
47+
"setasign/tfpdf": "Use this package to generate PDF files",
4748
"php-webdriver/webdriver": "Use this package, if you want to run tests with SeleniumTestCase"
4849
},
4950
"autoload": {

src/wcmf/lib/pdf/PDF.php

+24-6
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,37 @@
1010
*/
1111
namespace wcmf\lib\pdf;
1212

13-
use setasign\Fpdi\Fpdi;
13+
use setasign\Fpdi\Tfpdf\Fpdi;
1414

15-
if (!class_exists('setasign\Fpdi\Fpdi')) {
15+
if (!class_exists('setasign\Fpdi\Tfpdf\Fpdi')) {
1616
throw new \wcmf\lib\config\ConfigurationException(
1717
'wcmf\lib\pdf\PDF requires '.
18-
'Fpdi. If you are using composer, add setasign/fpdf and setasign/fpdi '.
18+
'Fpdi. If you are using composer, add setasign/tfpdf and setasign/fpdi '.
1919
'as dependency to your project');
2020
}
2121

2222
/**
23-
* PDF extends setasign\Fpdi\Fpdi.
23+
* NOTE ON USING FONTS
24+
*
25+
* If tFPDF (https://github.com/Setasign/tFPDF) is used as base class, proceed as follows:
26+
*
27+
* 1. Create a fonts directory and set FPDF_FONTPATH accordingly:
28+
*
29+
* define('FPDF_FONTPATH', dirname(__FILE__).'/fonts/');
30+
*
31+
* 2. Create a unifont directory inside the font directory and put ttfonts.php from the tFPDF package inside
32+
* 3. Put *.ttf fonts inside the unifont directory (no need for any conversion) and add them to the PDF instance:
33+
*
34+
* $this->AddFont('Roboto-Regular', '', 'Roboto-Regular.ttf', true);
35+
*
36+
* (NOTE the 3rd parameter holds the font file name and the 4th parameter is set to true)
37+
*/
38+
39+
40+
/**
41+
* PDF extends setasign\Fpdi\Tfpdf\Fpdi.
2442
*
25-
* @note This class requires setasign\Fpdi\Fpdi
43+
* @note This class requires setasign\Fpdi\Tfpdf\Fpdi
2644
*
2745
* @author ingo herwig <[email protected]>
2846
*/
@@ -157,7 +175,7 @@ public function NbLines($w, $txt) {
157175
if($c==' ') {
158176
$sep=$i;
159177
}
160-
$l+=$cw[$c];
178+
$l+=isset($cw[$c]) ? intval($cw[$c]) : 0;
161179
if($l>$wmax) {
162180
if($sep==-1) {
163181
if($i==$j) {

src/wcmf/lib/pdf/PDFPage.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212

1313
/**
1414
* PDFPage instances define the content of a pdf page by using a
15-
* set of FPDF/FPDI commands inside the PDFPage::render method.
15+
* set of tFPDF/FPDI commands inside the PDFPage::render method.
1616
*
1717
* @author ingo herwig <[email protected]>
1818
*/
1919
interface PDFPage {
2020

2121
/**
2222
* Render data onto a pdf.
23-
* @param $pdf FPDF/FPDI instance to render onto
23+
* @param $pdf tFPDF/FPDI instance to render onto
2424
* @param $page The page number in the pdf document
2525
* @param $data An optional data object to get data from.
2626
*/

0 commit comments

Comments
 (0)