|
3 | 3 |
|
4 | 4 | class ImprovedFPDF extends \PhpSigepFPDF |
5 | 5 | { |
6 | | - |
7 | 6 | /** |
8 | 7 | * @var int |
9 | 8 | */ |
10 | 9 | private $lineHeightPadding = 33; |
| 10 | + |
11 | 11 | /** |
12 | 12 | * @var array |
13 | 13 | */ |
14 | 14 | private $_savedState = array(); |
15 | 15 |
|
| 16 | + private $javascript; |
| 17 | + private $n_js; |
| 18 | + |
16 | 19 | function __construct($orientation = 'P', $unit = 'mm', $size = 'A4') |
17 | 20 | { |
18 | 21 | parent::__construct($orientation, $unit, $size); |
@@ -138,6 +141,64 @@ function gdImage($im, $x=null, $y=null, $w=0, $h=0, $link='') |
138 | 141 | $data = ob_get_clean(); |
139 | 142 | $this->MemImage($data, $x, $y, $w, $h, $link); |
140 | 143 | } |
| 144 | + |
| 145 | + function AutoPrint($dialog = false) |
| 146 | + { |
| 147 | + //Open the print dialog or start printing immediately on the standard printer |
| 148 | + $param = ($dialog ? 'true' : 'false'); |
| 149 | + $script = "print($param);"; |
| 150 | + $this->IncludeJS($script); |
| 151 | + } |
| 152 | + |
| 153 | + function AutoPrintToPrinter($server, $printer, $dialog = false) |
| 154 | + { |
| 155 | + //Print on a shared printer (requires at least Acrobat 6) |
| 156 | + $script = "var pp = getPrintParams();"; |
| 157 | + |
| 158 | + if ($dialog) { |
| 159 | + $script .= "pp.interactive = pp.constants.interactionLevel.full;"; |
| 160 | + } else { |
| 161 | + $script .= "pp.interactive = pp.constants.interactionLevel.silent;"; |
| 162 | + } |
| 163 | + |
| 164 | + $script .= "pp.printerName = '" . $printer . "';"; |
| 165 | + $script .= "print(pp);"; |
| 166 | + $this->IncludeJS($script); |
| 167 | + |
| 168 | + } |
| 169 | + |
| 170 | + function IncludeJS($script) { |
| 171 | + $this->javascript=$script; |
| 172 | + } |
| 173 | + |
| 174 | + function _putjavascript() { |
| 175 | + $this->_newobj(); |
| 176 | + $this->n_js=$this->n; |
| 177 | + $this->_out('<<'); |
| 178 | + $this->_out('/Names [(EmbeddedJS) '.($this->n+1).' 0 R]'); |
| 179 | + $this->_out('>>'); |
| 180 | + $this->_out('endobj'); |
| 181 | + $this->_newobj(); |
| 182 | + $this->_out('<<'); |
| 183 | + $this->_out('/S /JavaScript'); |
| 184 | + $this->_out('/JS '.$this->_textstring($this->javascript)); |
| 185 | + $this->_out('>>'); |
| 186 | + $this->_out('endobj'); |
| 187 | + } |
| 188 | + |
| 189 | + function _putresources() { |
| 190 | + parent::_putresources(); |
| 191 | + if (!empty($this->javascript)) { |
| 192 | + $this->_putjavascript(); |
| 193 | + } |
| 194 | + } |
| 195 | + |
| 196 | + function _putcatalog() { |
| 197 | + parent::_putcatalog(); |
| 198 | + if (!empty($this->javascript)) { |
| 199 | + $this->_out('/Names <</JavaScript '.($this->n_js).' 0 R>>'); |
| 200 | + } |
| 201 | + } |
141 | 202 | } |
142 | 203 |
|
143 | 204 | //Stream handler to read from global variables |
|
0 commit comments