web 2.0

How to usd PHP & PDF - Multiple Column

How to usd PHP & PDF - Multiple Column Learn PHP how to using PHP and PDF file (Multiple Column)

ShotDev Focus:
- PHP & PDF (Multiple Column)

Example

php_pdf_column.php

  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <?php  
  7. require('fpdf.php');  
  8.   
  9. class PDF extends FPDF  
  10. {  
  11. //Current column  
  12. var $col=0;  
  13. //Ordinate of column start  
  14. var $y0;  
  15.   
  16. function Header()  
  17. {  
  18. //Page header  
  19. global $title;  
  20.   
  21. $this->SetFont('Arial','B',15);  
  22. $w=$this->GetStringWidth($title)+6;  
  23. $this->SetX((210-$w)/2);  
  24. $this->SetDrawColor(0,80,180);  
  25. $this->SetFillColor(230,230,0);  
  26. $this->SetTextColor(220,50,50);  
  27. $this->SetLineWidth(1);  
  28. $this->Cell($w,9,$title,1,1,'C',true);  
  29. $this->Ln(10);  
  30. //Save ordinate  
  31. $this->y0=$this->GetY();  
  32. }  
  33.   
  34. function Footer()  
  35. {  
  36. //Page footer  
  37. $this->SetY(-15);  
  38. $this->SetFont('Arial','I',8);  
  39. $this->SetTextColor(128);  
  40. $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');  
  41. }  
  42.   
  43. function SetCol($col)  
  44. {  
  45. //Set position at a given column  
  46. $this->col=$col;  
  47. $x=10+$col*65;  
  48. $this->SetLeftMargin($x);  
  49. $this->SetX($x);  
  50. }  
  51.   
  52. function AcceptPageBreak()  
  53. {  
  54. //Method accepting or not automatic page break  
  55. if($this->col<2)  
  56. {  
  57. //Go to next column  
  58. $this->SetCol($this->col+1);  
  59. //Set ordinate to top  
  60. $this->SetY($this->y0);  
  61. //Keep on page  
  62. return false;  
  63. }  
  64. else  
  65. {  
  66. //Go back to first column  
  67. $this->SetCol(0);  
  68. //Page break  
  69. return true;  
  70. }  
  71. }  
  72.   
  73. function ChapterTitle($num,$label)  
  74. {  
  75. //Title  
  76. $this->SetFont('Arial','',12);  
  77. $this->SetFillColor(200,220,255);  
  78. $this->Cell(0,6,"Paragraph $num : $label",0,1,'L',true);  
  79. $this->Ln(4);  
  80. //Save ordinate  
  81. $this->y0=$this->GetY();  
  82. }  
  83.   
  84. function ChapterBody($file)  
  85. {  
  86. //Read text file  
  87. $f=fopen($file,'r');  
  88. $txt=fread($f,filesize($file));  
  89. fclose($f);  
  90. //Font  
  91. $this->SetFont('Times','',12);  
  92. //Output text in a 6 cm width column  
  93. $this->MultiCell(60,5,$txt);  
  94. $this->Ln();  
  95. //Mention  
  96. $this->SetFont('','I');  
  97. $this->Cell(0,5,'(end of excerpt)');  
  98. //Go back to first column  
  99. $this->SetCol(0);  
  100. }  
  101.   
  102. function PrintChapter($num,$title,$file)  
  103. {  
  104. //Add chapter  
  105. $this->AddPage();  
  106. $this->ChapterTitle($num,$title);  
  107. $this->ChapterBody($file);  
  108. }  
  109. }  
  110.   
  111. $pdf=new PDF();  
  112. $title='Welcome to www.ShotDev.Com Version 2010';  
  113. $pdf->SetTitle($title);  
  114. $pdf->SetAuthor('Jules Verne');  
  115.   
  116. $pdf->PrintChapter(1,'ShotDev.Com File 1','shotdev1.txt');  
  117. $pdf->PrintChapter(2,'ShotDev.Com File 2','shotdev2.txt');  
  118.   
  119. $pdf->Output("shotdev/mypdf.pdf","F");  
  120. ?>  
  121.   
  122. PDF Created Click <a href="shotdev/mypdf.pdf">here</a> to Download  
  123.   
  124. </body>  
  125. </html>  

Create a php file and save to path root-path/myphp/

Run
http://localhost/myphp/php_pdf_column.php

Screenshot

PHP & PDF - Multiple Column
.
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.