test_pdf.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. class TestPDF extends FPDF {
  3. private $currentTextColor = [0, 0, 0];
  4. public function GetFontSize() {
  5. return $this->FontSizePt;
  6. }
  7. public function SetTextColor($r, $g = null, $b = null) {
  8. if($r != 192) {
  9. $this->currentTextColor = [$r, $g, $b];
  10. }
  11. parent::SetTextColor($r, $g, $b);
  12. }
  13. public function Write($height, $text, $link = "") {
  14. $font_size = $this->GetFontSize();
  15. if(empty($text)) {
  16. $text = "N/A";
  17. }
  18. if($text == "N/A") {
  19. $this->SetTextColor(192, 192, 192);
  20. }
  21. parent::Write($height, $text, $link);
  22. call_user_func_array([$this, "SetTextColor"], $this->currentTextColor);
  23. // Restore font size
  24. $this->SetFontSize($font_size);
  25. }
  26. public function Cell($width, $height = 0, $text = "", $border = 0, $line_mode = 0, $align = "", $fill = false, $link = "") {
  27. $font_size = $this->GetFontSize();
  28. if(empty($text)) {
  29. $text = "N/A";
  30. }
  31. if($text == "N/A") {
  32. $this->SetTextColor(192, 192, 192);
  33. $this->SetFontSize($font_size - 2);
  34. }
  35. parent::Cell($width, $height, $text, $border, $line_mode, $align, $fill, $link);
  36. call_user_func_array([$this, "SetTextColor"], $this->currentTextColor);
  37. // Restore font size
  38. $this->SetFontSize($font_size);
  39. }
  40. public function MoveX($adjustment) {
  41. $this->SetX($this->GetX() + $adjustment);
  42. }
  43. public function MoveY($adjustment) {
  44. $this->SetY($this->GetY() + $adjustment);
  45. }
  46. }
  47. ?>