example_018.php 4.6 KB

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