example_018.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. //============================================================+
  3. // File name : example_018.php
  4. // Begin : 2008-03-06
  5. // Last Update : 2011-10-01
  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 s.r.l.
  15. // Via Della Pace, 11
  16. // 09044 Quartucciu (CA)
  17. // ITALY
  18. // www.tecnick.com
  19. // info@tecnick.com
  20. //============================================================+
  21. /**
  22. * Creates an example PDF TEST document using TCPDF
  23. * @package com.tecnick.tcpdf
  24. * @abstract TCPDF - Example: RTL document with Persian language
  25. * @author Nicola Asuni
  26. * @since 2008-03-06
  27. */
  28. require_once('../config/lang/eng.php');
  29. require_once('../tcpdf.php');
  30. // create new PDF document
  31. $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  32. // set document information
  33. $pdf->SetCreator(PDF_CREATOR);
  34. $pdf->SetAuthor('Nicola Asuni');
  35. $pdf->SetTitle('TCPDF Example 018');
  36. $pdf->SetSubject('TCPDF Tutorial');
  37. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  38. // set default header data
  39. $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 018', PDF_HEADER_STRING);
  40. // set header and footer fonts
  41. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  42. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  43. // set default monospaced font
  44. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  45. //set margins
  46. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  47. $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  48. $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  49. //set auto page breaks
  50. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  51. //set image scale factor
  52. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  53. // set some language dependent data:
  54. $lg = Array();
  55. $lg['a_meta_charset'] = 'UTF-8';
  56. $lg['a_meta_dir'] = 'rtl';
  57. $lg['a_meta_language'] = 'fa';
  58. $lg['w_page'] = 'page';
  59. //set some language-dependent strings
  60. $pdf->setLanguageArray($lg);
  61. // ---------------------------------------------------------
  62. // set font
  63. $pdf->SetFont('dejavusans', '', 12);
  64. // add a page
  65. $pdf->AddPage();
  66. // Persian and English content
  67. $htmlpersian = '<span color="#660000">Persian example:</span><br />سلام بالاخره مشکل PDF فارسی به طور کامل حل شد. اینم یک نمونش.<br />مشکل حرف \"ژ\" در بعضی کلمات مانند کلمه ویژه نیز بر طرف شد.<br />نگارش حروف لام و الف پشت سر هم نیز تصحیح شد.<br />با تشکر از "Asuni Nicola" و محمد علی گل کار برای پشتیبانی زبان فارسی.';
  68. $pdf->WriteHTML($htmlpersian, true, 0, true, 0);
  69. // set LTR direction for english translation
  70. $pdf->setRTL(false);
  71. $pdf->SetFontSize(10);
  72. // print newline
  73. $pdf->Ln();
  74. // Persian and English content
  75. $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>';
  76. $pdf->WriteHTML($htmlpersiantranslation, true, 0, true, 0);
  77. // Restore RTL direction
  78. $pdf->setRTL(true);
  79. // set font
  80. $pdf->SetFont('aefurat', '', 18);
  81. // print newline
  82. $pdf->Ln();
  83. // Arabic and English content
  84. $pdf->Cell(0, 12, 'بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ',0,1,'C');
  85. $htmlcontent = 'تمَّ بِحمد الله حلّ مشكلة الكتابة باللغة العربية في ملفات الـ<span color="#FF0000">PDF</span> مع دعم الكتابة <span color="#0000FF">من اليمين إلى اليسار</span> و<span color="#009900">الحركَات</span> .<br />تم الحل بواسطة <span color="#993399">صالح المطرفي و Asuni Nicola</span> . ';
  86. $pdf->WriteHTML($htmlcontent, true, 0, true, 0);
  87. // set LTR direction for english translation
  88. $pdf->setRTL(false);
  89. // print newline
  90. $pdf->Ln();
  91. $pdf->SetFont('aealarabiya', '', 18);
  92. // Arabic and English content
  93. $htmlcontent2 = '<span color="#0000ff">This is Arabic "العربية" Example With TCPDF.</span>';
  94. $pdf->WriteHTML($htmlcontent2, true, 0, true, 0);
  95. // ---------------------------------------------------------
  96. //Close and output PDF document
  97. $pdf->Output('example_018.pdf', 'I');
  98. //============================================================+
  99. // END OF FILE
  100. //============================================================+