Skip to content

Commit a22b995

Browse files
Added feature to append javascript into PDF; Added 'auto print' feature enabling pdf start to print automatically after opening
1 parent 5a9e73c commit a22b995

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

src/PhpSigep/Pdf/ImprovedFPDF.php

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33

44
class ImprovedFPDF extends \PhpSigepFPDF
55
{
6-
76
/**
87
* @var int
98
*/
109
private $lineHeightPadding = 33;
10+
1111
/**
1212
* @var array
1313
*/
1414
private $_savedState = array();
1515

16+
private $javascript;
17+
private $n_js;
18+
1619
function __construct($orientation = 'P', $unit = 'mm', $size = 'A4')
1720
{
1821
parent::__construct($orientation, $unit, $size);
@@ -138,6 +141,64 @@ function gdImage($im, $x=null, $y=null, $w=0, $h=0, $link='')
138141
$data = ob_get_clean();
139142
$this->MemImage($data, $x, $y, $w, $h, $link);
140143
}
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+
}
141202
}
142203

143204
//Stream handler to read from global variables

0 commit comments

Comments
 (0)