1<?php
2//============================================================+
3// File name   : example_018.php
4// Begin       : 2008-03-06
5// Last Update : 2013-05-14
6//
7// Description : Example 018 for TCPDF class
8//               RTL document with Persian language
9//
10// Author: Nicola Asuni
11//
12// (c) Copyright:
13//               Nicola Asuni
14//               Tecnick.com LTD
15//               www.tecnick.com
16//               info@tecnick.com
17//============================================================+
18
19/**
20 * Creates an example PDF TEST document using TCPDF
21 * @package com.tecnick.tcpdf
22 * @abstract TCPDF - Example: RTL document with Persian language
23 * @author Nicola Asuni
24 * @since 2008-03-06
25 */
26
27// Include the main TCPDF library (search for installation path).
28require_once('tcpdf_include.php');
29
30// create new PDF document
31$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
32
33// set document information
34$pdf->SetCreator(PDF_CREATOR);
35$pdf->SetAuthor('Nicola Asuni');
36$pdf->SetTitle('TCPDF Example 018');
37$pdf->SetSubject('TCPDF Tutorial');
38$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
39
40// set default header data
41$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 018', PDF_HEADER_STRING);
42
43// set header and footer fonts
44$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
45$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
46
47// set default monospaced font
48$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
49
50// set margins
51$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
52$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
53$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
54
55// set auto page breaks
56$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
57
58// set image scale factor
59$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
60
61// set some language dependent data:
62$lg = Array();
63$lg['a_meta_charset'] = 'UTF-8';
64$lg['a_meta_dir'] = 'rtl';
65$lg['a_meta_language'] = 'fa';
66$lg['w_page'] = 'page';
67
68// set some language-dependent strings (optional)
69$pdf->setLanguageArray($lg);
70
71// ---------------------------------------------------------
72
73// set font
74$pdf->SetFont('dejavusans', '', 12);
75
76// add a page
77$pdf->AddPage();
78
79// Persian and English content
80$htmlpersian = '<span color="#660000">Persian example:</span><br />سلام بالاخره مشکل PDF فارسی به طور کامل حل شد. اینم یک نمونش.<br />مشکل حرف \"ژ\" در بعضی کلمات مانند کلمه ویژه نیز بر طرف شد.<br />نگارش حروف لام و الف پشت سر هم نیز تصحیح شد.<br />با تشکر از  "Asuni Nicola" و محمد علی گل کار برای پشتیبانی زبان فارسی.';
81$pdf->WriteHTML($htmlpersian, true, 0, true, 0);
82
83// set LTR direction for english translation
84$pdf->setRTL(false);
85
86$pdf->SetFontSize(10);
87
88// print newline
89$pdf->Ln();
90
91// Persian and English content
92$htmlpersiantranslation = '<span color="#0000ff">Hi, At last Problem of Persian PDF Solved completely. This is a example for it.<br />Problem of "jeh" letter in some word like "ویژه" (=special) fix too.<br />The joining of laa and alf letter fix now.<br />Special thanks to "Nicola Asuni" and "Mohamad Ali Golkar" for Persian support.</span>';
93$pdf->WriteHTML($htmlpersiantranslation, true, 0, true, 0);
94
95// Restore RTL direction
96$pdf->setRTL(true);
97
98// set font
99$pdf->SetFont('aefurat', '', 18);
100
101// print newline
102$pdf->Ln();
103
104// Arabic and English content
105$pdf->Cell(0, 12, 'بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ',0,1,'C');
106$htmlcontent = 'تمَّ بِحمد الله حلّ مشكلة الكتابة باللغة العربية في ملفات الـ<span color="#FF0000">PDF</span> مع دعم الكتابة <span color="#0000FF">من اليمين إلى اليسار</span> و<span color="#009900">الحركَات</span> .<br />تم الحل بواسطة <span color="#993399">صالح المطرفي و Asuni Nicola</span>  . ';
107$pdf->WriteHTML($htmlcontent, true, 0, true, 0);
108
109// set LTR direction for english translation
110$pdf->setRTL(false);
111
112// print newline
113$pdf->Ln();
114
115$pdf->SetFont('aealarabiya', '', 18);
116
117// Arabic and English content
118$htmlcontent2 = '<span color="#0000ff">This is Arabic "العربية" Example With TCPDF.</span>';
119$pdf->WriteHTML($htmlcontent2, true, 0, true, 0);
120
121// ---------------------------------------------------------
122
123//Close and output PDF document
124$pdf->Output('example_018.pdf', 'I');
125
126//============================================================+
127// END OF FILE
128//============================================================+
129