Cached_PDF_Decorator

Caching canvas implementation.

Defined (1)

The class is defined in the following location(s).

/lib/dompdf/include/cached_pdf_decorator.cls.php  
  1. class Cached_PDF_Decorator extends CPDF_Adapter implements Canvas { 
  2. /** 
  3. * @var CPDF_Adapter 
  4. */ 
  5. protected $_pdf; 
  6. protected $_cache_id; 
  7. protected $_current_page_id; 
  8. protected $_fonts; // fonts used in this document 
  9.  
  10. function __construct($paper = "letter", $orientation = "portrait", DOMPDF $dompdf) { 
  11. $this->_fonts = array(); 
  12.  
  13. /** 
  14. * Must be called after constructor 
  15. * @param int $cache_id 
  16. * @param CPDF_Adapter $pdf 
  17. */ 
  18. function init($cache_id, CPDF_Adapter $pdf) { 
  19. $this->_cache_id = $cache_id; 
  20. $this->_pdf = $pdf; 
  21. $this->_current_page_id = $this->_pdf->open_object(); 
  22.  
  23. //........................................................................ 
  24.  
  25. function get_cpdf() { return $this->_pdf->get_cpdf(); } 
  26.  
  27. function open_object() { $this->_pdf->open_object(); } 
  28. function reopen_object($object) { $this->_pdf->reopen_object($object); } 
  29.  
  30. function close_object() { $this->_pdf->close_object(); } 
  31.  
  32. function add_object($object, $where = 'all') { $this->_pdf->add_object($object, $where); } 
  33.  
  34. function serialize_object($id) { $this->_pdf->serialize_object($id); } 
  35.  
  36. function reopen_serialized_object($obj) { $this->_pdf->reopen_serialized_object($obj); } 
  37.  
  38. //........................................................................ 
  39.  
  40. function get_width() { return $this->_pdf->get_width(); } 
  41. function get_height() { return $this->_pdf->get_height(); } 
  42. function get_page_number() { return $this->_pdf->get_page_number(); } 
  43. function get_page_count() { return $this->_pdf->get_page_count(); } 
  44.  
  45. function set_page_number($num) { $this->_pdf->set_page_number($num); } 
  46. function set_page_count($count) { $this->_pdf->set_page_count($count); } 
  47.  
  48. function line($x1, $y1, $x2, $y2, $color, $width, $style = array()) { 
  49. $this->_pdf->line($x1, $y1, $x2, $y2, $color, $width, $style); 
  50.  
  51. function rectangle($x1, $y1, $w, $h, $color, $width, $style = array()) { 
  52. $this->_pdf->rectangle($x1, $y1, $w, $h, $color, $width, $style); 
  53.  
  54. function filled_rectangle($x1, $y1, $w, $h, $color) { 
  55. $this->_pdf->filled_rectangle($x1, $y1, $w, $h, $color); 
  56.  
  57. function polygon($points, $color, $width = null, $style = array(), $fill = false) { 
  58. $this->_pdf->polygon($points, $color, $width, $style, $fill); 
  59.  
  60. function circle($x, $y, $r1, $color, $width = null, $style = null, $fill = false) { 
  61. $this->_pdf->circle($x, $y, $r1, $color, $width, $style, $fill); 
  62.  
  63. function image($img_url, $x, $y, $w, $h, $resolution = "normal") { 
  64. $this->_pdf->image($img_url, $x, $y, $w, $h, $resolution); 
  65.  
  66. function text($x, $y, $text, $font, $size, $color = array(0, 0, 0), $word_space = 0.0, $char_space = 0.0, $angle = 0.0) { 
  67. $this->_fonts[$font] = true; 
  68. $this->_pdf->text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle); 
  69.  
  70. function page_text($x, $y, $text, $font, $size, $color = array(0, 0, 0), $word_space = 0.0, $char_space = 0.0, $angle = 0.0) { 
  71.  
  72. // We want to remove this from cached pages since it may not be correct 
  73. $this->_pdf->close_object(); 
  74. $this->_pdf->page_text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle); 
  75. $this->_pdf->reopen_object($this->_current_page_id); 
  76.  
  77. function page_script($script, $type = 'text/php') { 
  78.  
  79. // We want to remove this from cached pages since it may not be correct 
  80. $this->_pdf->close_object(); 
  81. $this->_pdf->page_script($script, $type); 
  82. $this->_pdf->reopen_object($this->_current_page_id); 
  83.  
  84. function new_page() { 
  85. $this->_pdf->close_object(); 
  86.  
  87. // Add the object to the current page 
  88. $this->_pdf->add_object($this->_current_page_id, "add"); 
  89. $this->_pdf->new_page();  
  90.  
  91. Page_Cache::store_page($this->_cache_id,  
  92. $this->_pdf->get_page_number() - 1,  
  93. $this->_pdf->serialize_object($this->_current_page_id)); 
  94.  
  95. $this->_current_page_id = $this->_pdf->open_object(); 
  96. return $this->_current_page_id; 
  97.  
  98. function stream($filename, $options = null) { 
  99. // Store the last page in the page cache 
  100. if ( !is_null($this->_current_page_id) ) { 
  101. $this->_pdf->close_object(); 
  102. $this->_pdf->add_object($this->_current_page_id, "add"); 
  103. Page_Cache::store_page($this->_cache_id,  
  104. $this->_pdf->get_page_number(),  
  105. $this->_pdf->serialize_object($this->_current_page_id)); 
  106. Page_Cache::store_fonts($this->_cache_id, $this->_fonts); 
  107. $this->_current_page_id = null; 
  108.  
  109. $this->_pdf->stream($filename); 
  110.  
  111.  
  112. function output($options = null) { 
  113. // Store the last page in the page cache 
  114. if ( !is_null($this->_current_page_id) ) { 
  115. $this->_pdf->close_object(); 
  116. $this->_pdf->add_object($this->_current_page_id, "add"); 
  117. Page_Cache::store_page($this->_cache_id,  
  118. $this->_pdf->get_page_number(),  
  119. $this->_pdf->serialize_object($this->_current_page_id)); 
  120. $this->_current_page_id = null; 
  121.  
  122. return $this->_pdf->output(); 
  123.  
  124. function get_messages() { return $this->_pdf->get_messages(); } 
  125.